JavaScript solution


  • 0
    W
    var twoSum = function(nums, target) {
        let obj = {};
        for(let i=0;i<nums.length;i++){
            let complement = target - nums[i];
            if(obj.hasOwnProperty(complement)){
                return [obj[complement],i];
            }
            obj[nums[i]] = i;
        }
    };
    

Log in to reply
 

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