C++ solution with stl container set


  • 1
    bool containsDuplicate(vector<int>& nums) {
        set<int> nums_set;
        for( auto i : nums)
        {
            auto check = nums_set.find(i);
            if( check == nums_set.end())
                nums_set.insert(i);
            else
                return true;
        }
        return false;
    }

Log in to reply
 

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