Skip to content

Instantly share code, notes, and snippets.

@kcliu
Created July 14, 2016 09:51
Show Gist options
  • Save kcliu/22972d6a6ac47e33364c0db3cfd09a76 to your computer and use it in GitHub Desktop.
Save kcliu/22972d6a6ac47e33364c0db3cfd09a76 to your computer and use it in GitHub Desktop.
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function(nums, target) {
dict = {};
for(i = 0; i < nums.length; i++) {
dict[nums[i]] = i;
}
for(i = 0; i < nums.length; i++) {
j = dict[target - nums[i]];
if (j) {
return [i, j];
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment