Created
February 28, 2021 11:25
-
-
Save MohammedALREAI/0e9c2f79920242fb46e6cd0feb6eb3f9 to your computer and use it in GitHub Desktop.
firstDuplicate google
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
function firstDuplicate(a: number[]=[2, 1, 3, 5, 3, 2]): number { | |
let set = new Set() | |
for (let e of a){ | |
if (set.has(e)) | |
return e | |
else | |
set.add(e) | |
} | |
return -1 | |
} | |
console.log(firstDuplicate()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment