Created
August 4, 2018 22:30
-
-
Save minmaxdata/b6e45aef85f9477fe7425240f5e2b42a to your computer and use it in GitHub Desktop.
Javascript Hash
This file contains hidden or 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
var twoSum = function(nums, target) { | |
const hash = {}; | |
for (let i = 0; i < nums.length; i++) { | |
const comp = target - nums[i]; | |
if (hash[comp] !== undefined) { | |
return [hash[comp], i]; | |
} | |
hash[nums[i]] = i; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment