LC 1. Two Sum
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| /**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function(nums, target) {
const map = new Map()
for (let i =0; i < nums.length; i++) {
const x = target - nums[i]
if (map.has(x)) {
return [map.get(x), i]
}
map.set(nums[i], i)
}
};
|
评论和交流请发送邮件到 me@tianhegao.com