public class Solution {
public int majorityElement(int[] nums) {
if (nums == null  nums.length == 0) return 0;
int cnt = 0;
int candidate = 0;
for(int i = 0; i < nums.length; i++) {
if (cnt == 0) {
candidate = nums[i];
cnt = 1;
} else if (nums[i] == candidate) {
cnt++;
} else {
cnt;
}
}
return candidate;
}
}
Java  BoyerMoore implementation O(n)



@guilhebl thanks, google leads me to "Boyer–Moore string search algorithm" when I search Boyer Moore

@LuckyPants yes the most famous boyer moore algorithm is the search one, not sure if this was created by the same authors but it has the same name although dealing with different problems