Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nickforce/7f8acd94cab8f5850ddf90652c8fa13a to your computer and use it in GitHub Desktop.
Save nickforce/7f8acd94cab8f5850ddf90652c8fa13a to your computer and use it in GitHub Desktop.
Two Sum (leetcode)
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function(nums, target) {
let numObj = {}
for(i = 0; i < nums.length; i++) {
let other = target - nums[i];
if(numObj[other] !== undefined) {
return [numObj[other], i];
}
numObj[nums[i]] = i;
}
};
console.log(twoSum([3,3], 6));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment