标签:display dex get com let 技术 image function tar
解法1 两次for或者for+indexOf
var twoSum = function (nums, target) {
let len = nums.length
for (let i = 0; i < len; i++) {
let j = nums.indexOf(target - nums[i], i + 1)
if (j !== -1) {
return [i, j]
}
}
};

解法2
var twoSum = function (nums, target) {
let map = new Map()
for (let i = 0; i < nums.length; i++) {
let j = target - nums[i]
if(map.has(j)){
return [map.get(j),i]
}
map.set(nums[i],i)
}
};


标签:display dex get com let 技术 image function tar
原文地址:https://www.cnblogs.com/Mijiujs/p/12424029.html