Created
April 26, 2026 14:11
-
-
Save thinkphp/f6b77c35e10272c27b18b27cca522d95 to your computer and use it in GitHub Desktop.
Boyer Moore Algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Algoritmul Boyer Moore Vote MAjority Element | |
| int count = 0 | |
| int candidate = 0 | |
| for(int num: nums) { | |
| if(count == 0) { | |
| candidate = num | |
| } | |
| if(num === candidate ) { | |
| count++; | |
| } else { | |
| count--; | |
| } | |
| } | |
| return candidate //element majoritar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment