/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function(nums, target) {
const memo = {};
for (let i = 0; i < nums.length; i++) {
const num = nums[i];
const diff = target - num;
if (memo[num] !== undefined) {
return [i, memo[num]];
} else {
memo[diff] = i;
}
}
return [];
};