/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function (nums, target) {
const hash = {}
for (let i = 0; i < nums.length; i++) {
const cur = nums[i];
// 需要考虑索引为 0 的情况
if (hash[cur] !== undefined) {
return [hash[cur], i]
}
const next = target - cur
hash[next] = i
}
};
console.log(twoSum([2, 7, 11, 15], 9))