Tianhe Gao

LC 1. Two Sum

 1/**
 2 * @param {number[]} nums
 3 * @param {number} target
 4 * @return {number[]}
 5 */
 6var twoSum = function(nums, target) {
 7  const map = new Map()
 8  for (let i =0; i < nums.length; i++) {
 9    const x = target - nums[i]
10    if (map.has(x)) {
11      return [map.get(x), i]
12    }
13    map.set(nums[i], i)
14  }
15};

No notes link to this note

Welcome to tell me your thoughts via "email"
UP