A 52ms C++ Solution Using Uordered_map


  • 0
    Y
    class Solution {
    public:
        bool containsDuplicate(vector<int>& nums) {
            unordered_map<int,int> myMap;
            for(int i = 0; i < nums.size(); i++) {
                if(myMap.find(nums[i]) != myMap.end()) return true;
                myMap.insert({nums[i],i});
            }
            return false;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.