3 lines of c++, using set


  • 2
    P
    class Solution {
    public:
    
        bool containsDuplicate(vector<int>& nums) {
            
           std::set<int> s;
           for(int i = 0 ; i < nums.size(); i++) s.insert(nums.at(i));
           return s.size() != nums.size();
        }
    };

  • 5
    M

    it is slower than

    std::set<int> s(nums.begin(), nums.end());
    return s.size() != nums.size();


Log in to reply
 

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