1. 两数之和
代码:
1 var twoSum = function(nums, target) { 2 let mem = new Map(); 3 for(let i = 0; i < nums.length; i++){ 4 if(mem.has(target-nums[i])){ 5 return [mem.get(target-nums[i]), i]; 6 } 7 mem.set(nums[i], i); 8 } 9 return [undefined, undefined]; 10 };