题目描述:
思路:
首先使用哈希表记录每个数字出现次数
然后找到与N相等的次数的数字
代码如下:
class Solution {
public:
int repeatedNTimes(vector<int>& A) {
int N=A.size()/2;
map<int,int>cnt;
for(int i=0;i<A.size();i++){
cnt[A[i]]++;
}
for(int i=0;i<A.size();i++){
if(cnt[A[i]]==N)
return A[i];
}
return 0;
}
};