-
-
Save tin80122/19707f325f6fb0c8491b99bbe2d8b339 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 ary = s.split(''); | |
var counter = {}; | |
for(var i = 0; i< ary.length; i++){ | |
if(!(ary[i] in counter)){ | |
counter[ary[i]] = 1; | |
}else{ | |
counter[ary[i]] += 1; | |
} | |
} | |
console.log(counter); | |
Object.keys(counter).map(function(key,index){ | |
if(counter[key] === 1){ | |
return key; | |
}else{ | |
return -1; | |
} | |
}) | |
for(var j = 0 ; j < counter.lenght ; j++){ | |
console.log(counter[j]); | |
} | |
}; | |
var a = firstUniqChar("leetcode"); | |
console.log(a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment