Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

two sum js

function sumDigit(nums, target) {
  let mapping = {}

  for(let i = 0; i < nums.length; i++) {
    let n = nums[i]

    if(mapping[target - n] != null) return [ mapping[target - n], i ]
    mapping[n] = i
  }
}

sumDigit([3,2,4], 6)
Source by leetcode.com #
 
PREVIOUS NEXT
Tagged: #sum #js
ADD COMMENT
Topic
Name
6+3 =