题目链接:https://leetcode-cn.com/problems/contains-duplicate/
题目如下:
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
//tip:
//1、unordered_map 在#include <unordered_map>中,unordered_set 在#include<unordered_set>中
//2、unordered_map 和 map的区别:
// map会按照键值对的键 key 进行排序;unordered_map省去了这个排序的过程
//3、unordered_set和set的区别:
// set会按集合中的元素大小从小到大进行排序;unordered_set省去了这个排序的过程
unordered_map<int,int> hash;
for(auto e:nums){
hash[e]++;
if(hash[e]==2) return true;
}
return false;
}
};