Skip to content

Instantly share code, notes, and snippets.

@yevmoroz
Created April 16, 2024 00:36
Show Gist options
  • Save yevmoroz/167c73b5c77175b1643e746e94057353 to your computer and use it in GitHub Desktop.
Save yevmoroz/167c73b5c77175b1643e746e94057353 to your computer and use it in GitHub Desktop.
leetcode sum of 2 from list
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
function twoSum(nums, target) {
let mp = new Map()
for (let i = 0; i < nums.length; i++) {
let diff = target - nums[i]
if (mp.has(diff)) {
return [i, mp.get(diff)]
}
mp.set(nums[i], i)
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment