算法1
$O(n)$
C++ 代码
#include <iostream>
using namespace std;
const int N =10010;
int arr[N], n,t;
int main(){
cin >> n;
int ans =-1; int count = -1;
for(int i = 0; i <n;i++){
cin >> t;arr[t]++;
if(arr[t] > count){ans = t;count = arr[t];
}else if(arr[t] == count && ans > t){ ans = t;}
}
cout << ans<<endl;
return 0;
}