1 2 3 4 5 6 7 8 9 10 11 12
var twoSum = function(nums, target) { const pairIdx = {}; for (let i = 0; i < nums.length; i++) { const num = nums[i]; if (target - num in pairIdx) { return [i, pairIdx[target - num]]; } pairIdx[num] = i; } };