https://leetcode.com/problems/contains-duplicate/description/
Solution 1. Use a map.
bool containsDuplicate(vector<int>& nums) {
unordered_map<int,int> m;
for(int n: nums) {
m[n]++;
if(m[n]==2) return true;
}
return false;
}
No comments:
Post a Comment