Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.
You may assume that the array is non-empty and the majority element always exist in the array.
int majorityElement(int num[], int n) {
int tmp,count=0;
tmp=num[0];
for(int i=1;i<n;i++){
if(tmp!=num[i]&&count==0)
tmp=num[++i];
else if(tmp==num[i])
count++;
else count--;
}
return tmp;
}