class Solution {
public:
int findDuplicate(vector<int>& nums) {
unordered_map<int, int> map;
int res = 0;
for (int i = 0; i<nums.size(); i++) {
if (map[nums[i]]==0) {
map[nums[i]]++;
}else{
res = nums[i];
}
}
return res;
}
};
Find the Duplicate Number
Copyright © 2017 Powered by LZH, Theme used GitHub CSS.