Javascript very fast solution


  • 4
    L
    var containsDuplicate = function(nums) {
        var obj = {};
        
        for(var i = 0; i < nums.length; i++){
            obj[nums[i]] = obj[nums[i]] + 1 || 1;
            
            if(obj[nums[i]] > 1) return true;
        }
        
        return false;
    };

  • 1
    B

    Can you explain the logic behind this code?


Log in to reply
 

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