leetcode讲解--217. Contains Duplicate
文章目录
217. Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
so easy的一道题。我直接上代码吧:
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
unordered_map<int, int> hash;
for(auto i:nums){
hash[i]++;
}
for(auto i:hash){
if(i.second>=2)
return true;
}
return false;
}
};
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论