[230907] Leetcode - 1. Two Sum
Leetcode - 1. Two Sum
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function (nums, target) {
const hash = {}
for (i = 0; i < nums.length; i++) {
const findValue = target - nums[i];
if (hash[findValue] !== undefined) return [i, hash[findValue]]
hash[nums[i]] = i;
}
};
Leave a comment