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.app
so easy的一道題。我直接上代碼吧:code
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; } };