Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created April 26, 2026 14:11
Show Gist options
  • Select an option

  • Save thinkphp/f6b77c35e10272c27b18b27cca522d95 to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/f6b77c35e10272c27b18b27cca522d95 to your computer and use it in GitHub Desktop.
Boyer Moore Algorithm
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