Simple - Easy to understand- C++ Solution - Sort not required


  • 0
    V
    class Solution {
    public:
        bool containsDuplicate(vector<int>& nums) {
            std::unordered_map<int, int> duplicate;
            for(auto& i : nums){
                if(++duplicate[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.