Skip to content

Instantly share code, notes, and snippets.

@remi-bruguier
Created May 16, 2020 12:37
Show Gist options
  • Save remi-bruguier/2ed88c58a3a528778bb6377cbbe2f0e1 to your computer and use it in GitHub Desktop.
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.
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