Last active
October 20, 2023 19:29
-
-
Save leleofg/d677574ce3599986e8b191494e7d8a8b to your computer and use it in GitHub Desktop.
twosum-leetcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function twoSum(nums: number[], target: number): number[] { | |
let map = new Map(); | |
for (let i = 0; i < nums.length; i++) { | |
let complement = target - nums[i]; | |
if (map.has(complement)) { | |
return [map.get(complement), i]; | |
} else { | |
map.set(nums[i], i); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment