AC javascript solution


  • 0
    Z
    var twoSum = function(nums, target) {
       var numset = {};
       var res = [];
       for(var i = 0; i<nums.length; i++)
       {
         if(numset[target-nums[i]] != undefined)
         {
           res.push(numset[target-nums[i]]);
           res.push(i);
           return res
         }
         else
         {
           numset[nums[i]]=i;
         }
       } 
    };
    

Log in to reply
 

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