44 ms C++ version solution


  • 1
    bool containsDuplicate(vector<int>& nums) {
        sort(nums.begin(),nums.end());
        if(nums.size()==1){
            return false;
        }
        for(int i=0,n=nums.size();i<n-1;i++) {
            if(nums[i]==nums[i+1]) {
                return true;
            }
        }
        return false;
    }
    

    Sort first and compare consecutive numbers. it's O(nlgn) I think.


  • 0
    C

    I think the point is to implement your own version of "Sort".


Log in to reply
 

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