Created
May 16, 2020 12:37
-
-
Save remi-bruguier/2ed88c58a3a528778bb6377cbbe2f0e1 to your computer and use it in GitHub Desktop.
Return whether or not there are two numbers in the list that add up to k.
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
const twoSum = (numbers:number[], k: number): Boolean => { | |
const rec:Record<number,number>= {}; | |
for(const n of numbers){ | |
rec[n] = n; | |
if(rec.hasOwnProperty(k-n)) return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment