/*Hash Table*/
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
unordered_map<int, int> count;
for(int i = 0; i < nums.size(); ++i){
if(count.find(nums[i]) != count.end()) ++count[nums[i]];
else count[nums[i]] = 1;
}
for(unordered_map<int, int>::iterator it = count.begin(); it != count.end(); ++it){
if(it->second > 1) return true;
}
return false;
}
};
LeetCode之Contains Duplicate
最新推荐文章于 2020-02-07 15:16:07 发布