push_back is faster than = in vector!
设置头尾两个指针
int majorityElement(vector<int>& nums) {
int c=1;
int n=nums[0];
int i;
for(i=1;i<nums.size();i++)
{
if(nums[i]==n)
c++;
else
c--;
if(c==0)
{
c=1;
n=nums[i];
}
}
return n;
}
Majority Voting Algorithm Moore voting