Javascript solution using set


  • 0
    S

    var findDuplicate = function(nums) {
    var len = nums.length;
    var mp= new Set();
    mp.add(nums[0]);
    for(x=1;x<nums.length;x++){
    if(mp.has(nums[x])){
    return nums[x]
    } else {
    mp.add(nums[x]);
    }
    }
    return tsum-arrSum;
    };


Log in to reply
 

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