function twoSum(nums, target) {
let result = [],
cache = {};
for (let i = 0; i < nums.length; i++) {
let x = target - nums[i];
if (cache[x] !== undefined) {
result.push([cache[x], i]);
}
cache[nums[i]] = i;
}
return result;
};
Categories