3 lines C++


  • 0

    3 lines using unordered_map

        bool containsDuplicate(vector<int>& nums) {
            unordered_map<int,int>m;
            for(auto x: nums){ if(m[x]>0) return true; m[x]++;}
            return false;
        }
    

    And one line using set

        bool containsDuplicate(vector<int>& nums) {
            return set<int>(nums.begin(), nums.end()).size() < nums.size();
        }
    

Log in to reply
 

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