Skip to content

Instantly share code, notes, and snippets.

@leleofg
Last active October 20, 2023 19:29
Show Gist options
  • Save leleofg/d677574ce3599986e8b191494e7d8a8b to your computer and use it in GitHub Desktop.
Save leleofg/d677574ce3599986e8b191494e7d8a8b to your computer and use it in GitHub Desktop.
twosum-leetcode
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