在字符串 s 中找出第一个只出现一次的字符。如果没有,返回一个单空格。 s 只包含小写字母。
示例:
s = "abaccdeff"
返回 "b"
s = ""
返回 " "
题解:
/**
* @param {string} s
* @return {character}
*/
var firstUniqChar = function(s) {
let dict = {}
let i=0
while(s[i]){
if(s[i] in dict){
dict[s[i]] = dict[s[i]]+1
}else{
dict[s[i]] = 1
}
i++
}
i=0
while(dict[s[i]]){
if(dict[s[i]]==1){
return s[i]
}
i++
}
return " "
};
链接:https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof