a five line hash solution


  • 1
    T
    /**
     * @param {number[]} nums
     * @return {boolean}
     */
    var containsDuplicate = function(nums) {
        var hash={};
        for(var i=0;i<nums.length;i++){
            if(hash[nums[i]]) return true;
            hash[nums[i]]=1;
        }
        return false;
    };
    

Log in to reply
 

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