在长度 2N 的数组中找出重复 N 次的元素
题目来源:leetcode
class Solution {
public:
int repeatedNTimes(vector<int>& nums) {
unordered_map<int,int> cmap;
for(auto e: nums)
{
cmap[e]++;
}
for(auto& kv : cmap)
{
if(kv.second == nums.size() / 2)
{
return kv.first;
}
}
return -1;
}
};