Intuitive Javascript Solution


  • 0
    D
    var containsDuplicate = function(nums) {
        nums.sort();
        // duplicate numbers locate side by side in sorted array
        for (const [i, n] of nums.entries())
            if (i > 0 && n === nums[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.