-
-
Save tin80122/85018f0285fee81d31369c5d01fd7e19 to your computer and use it in GitHub Desktop.
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
var firstUniqChar = function(s) { | |
var counter = new Map(); | |
for(let word of s){ | |
if(word === undefined) | |
break; | |
if(!(counter.has(word))){ | |
counter.set(word,1); | |
}else{ | |
counter.set(word,counter.get(word)+1); | |
} | |
} | |
for(let [key,value] of counter){ | |
if(counter.get(key) === 1){ | |
return s.search(key); | |
} | |
} | |
return -1; | |
}; | |
var a = firstUniqChar("leetcode"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment