Short Javascript one pass


  • 0
    O
    var twoSum = function(nums, target) {
        var numHash = {}, len = nums.length, c;
        
        for(var i=0; i<len;  i++){
            c = target-nums[i];
            if( c in numHash )  return [ numHash[c], i ];
            numHash[nums[i]] = i;
        }
        
        return [];
    };

Log in to reply
 

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