Skip to content

Instantly share code, notes, and snippets.

@tin80122
Created August 19, 2019 06:45
Show Gist options
  • Save tin80122/85018f0285fee81d31369c5d01fd7e19 to your computer and use it in GitHub Desktop.
Save tin80122/85018f0285fee81d31369c5d01fd7e19 to your computer and use it in GitHub Desktop.
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