Accepted Javascript solution


  • 0
    L
    /**
     * @param {number[]} nums
     * @param {number} target
     * @return {number[]}
     */
    var twoSum = function(nums, target) {
     
      var map = {};
        
      for (i = 0; i < nums.length; i++) {
          if(map[target-nums[i]] !== undefined){
              //get result
              return [map[target-nums[i]], i];
          }else{
              map[nums[i]] = i;
          }
      }
        
    };

Log in to reply
 

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