SOURCE

function twoSum(nums, target) {
    const hashMap = {};
    for(let i = 0; i < nums.length; i += 1){
        if (hashMap[target-nums[i]]) {
            return [hashMap[target-nums[i]], i];
        }
        hashMap[nums[i]] = i;
    }
    return []
}

console.log(twoSum([1,5,4,2,7,8], 7));
console 命令行工具 X clear

                    
>
console