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             };

 

posted @ 2022-04-02 17:43  BJFU-VTH  阅读(26)  评论(0编辑  收藏  举报