Created
February 28, 2021 11:24
-
-
Save MohammedALREAI/a2323a31eafab841e4c7f032c650d756 to your computer and use it in GitHub Desktop.
firstNotRepeatingCharacter typescript
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
interface Imap{ | |
[key:string]:number | |
} | |
function firstNotRepeatingCharacter(s: string="abacabad"): string { | |
let map:Imap ={} | |
for (let e of s){ | |
if(e in map){ | |
map[e]=map[e]+1 | |
} | |
else | |
map[e]=1 | |
} | |
for (let e in map) | |
if (map[e] == 1) | |
return e | |
return '_' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment