Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

two sum js

var twoSum = function(nums, target) {
let mapping = {}

  for(let i = 0; i < nums.length; i++) {
      if(target - nums[i] in mapping) {
         return [mapping[target-nums[i]],i]
      } else {
         mapping[nums[i]] = i
      }
  }
  return []
};
Source by leetcode.com #
 
PREVIOUS NEXT
Tagged: #sum #js
ADD COMMENT
Topic
Name
9+5 =