leetcode-两数之和
const target = 9 let nums = [2,11,7,15] let res = [0,1] let record_map = new Map() function main(){ if( nums.length<=2) { return res } for (var i = nums.length - 1; i >= 0; i--) { if(!record_map.has(target - nums[i])){ record_map.set(nums[i],i) }else{ res=[] res.push(i) res.push(record_map.get(target-nums[i])) break } } console.log(res) return res }
nhz94259@163.com