int majorityElement(int num[], int n) {
int i = 0;
int result = 0;
int count = 0;
for (;i < n; ++i) {
if (count == 0  result == num[i]) {
result = num[i];
count++;
} else {
count;
}
}
return result;
}
Share my 10ms c solution

It's BoyerMoore majority vote algorithm,you can refer to this link http://www.cs.rug.nl/~wim/pub/whh348.pdf .
Accroding to the problem description, we have known that the majority element always exist in the array,so the first iteration will get the result.