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.
判断数组中是否有重复元素,各种做法,解法太多了。
代码语言:javascript复制class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
unordered_map<int, int> mp;
for(int i = 0; i < nums.size(); i )
{
mp[nums[i]] ;
if(mp[nums[i]] > 1) return true;
}
return false;
}
};