解题思路:
既然N+1个数长度为2N,那么只要出现大于2的就是重复的数,返回即可,用map进行记录,代码如下:
class Solution {
public:
int repeatedNTimes(vector& nums) {
unordered_map mp;
for(auto& num : nums) {
mp[num] ++;
if(mp[num] > 1) return num;
}
return 0;
}
};


![LeetCode 961 在长度2N的数组中找出重复N次的元素[map] HERODING的LeetCode之路 LeetCode 961 在长度2N的数组中找出重复N次的元素[map] HERODING的LeetCode之路](http://www.mshxw.com/aiimages/31/920245.png)
