217. Contains Duplicate
HashMap
class Solution {
public:
bool containsDuplicate(vector<int>& nums)
{
unordered_map<int, int> freq;
for (auto num : nums) ++freq[num];
for (auto [k, v] : freq)
{
if (v > 1) return true;
}
return false;
}
};
- T:
- S: