leetcode 1
var twoSum = function(nums, target) {
let map = new Map()
for (let i = 0; i < nums.length; i++) {
if (map.has(target - nums[i])) {
return [map.get(target - nums[i]),i]
}
map.set(nums[i], i);
}
return [-1,-1];
};
leetcode 1
var twoSum = function(nums, target) {
let map = new Map()
for (let i = 0; i < nums.length; i++) {
if (map.has(target - nums[i])) {
return [map.get(target - nums[i]),i]
}
map.set(nums[i], i);
}
return [-1,-1];
};
本文标题:twoSum:找到和为target的2个数
本文链接:https://www.haomeiwen.com/subject/zvjxhktx.html
网友评论