内存限制4mb
用数组不通过,怎么办?
众数出现的次数必须大于n/2
第一行输入一个整数n (1<=n<=1E6)
接下来一行n个整数 mi (1<=MI<=1E9) 表示第i种糖果的个数,整数之间用空格隔开
输出mi中出现次数最多的那个数,占一行
5
10 10 10 20 30
10
#include<stdio.h>
int main()
{
int n,t,x,top;
scanf("%d",&n);
top=t=0;
for(int i=1;i<=n;++i)
{
scanf("%d",&x);
if(x==t)
top++;
else if(top==0)
{
t=x;
top=1;
}
else top--;
}
printf("%d\n",t);
return 0;
}