#include<iostream>
using namespace std;
void find(int A[],int length)
{
int times=0;
int i=0;
int temp;
for(;i<length;++i)
{
if(times==0)
{
temp=A[i];
times=1;
}
else
{
if(A[i]==temp)
times++;
else
times--;
}
}
cout<<temp<<endl;
}
int main()
{
int a[]={1,1,1,2,2,2};
find(a,5);
system("pause");
return 0;
}寻找发帖水王(找出数组出现超过一半的数字)
原文:http://blog.csdn.net/qq_22335577/article/details/45011419