C++ simple solution using map.


  • 0
    T
    class Solution {
    public:
        bool containsDuplicate(vector<int>& nums) {
            std::map<int, int> hmap;
            
            for (int i = 0; i < nums.size(); i++) {
                if (++hmap[nums[i]] > 1) 
                    return true;
            }
            
            return false;
        }
    };
    

Log in to reply
 

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