面试题50 第一个只出现一次的字符
示例
js
s = "abaccdeff"
返回 "b"
s = ""
返回 " "
s = "abaccdeff"
返回 "b"
s = ""
返回 " "
JS
js
/**
* @param {string} s
* @return {character}
*/
var firstUniqChar = function (s) {
let map = {}
for (c of s) {
if (map[c]) {
map[c]++;
} else {
map[c] = 1
}
}
for (c of s) {
if (map[c] === 1) {
return c
}
}
return ' '
};
/**
* @param {string} s
* @return {character}
*/
var firstUniqChar = function (s) {
let map = {}
for (c of s) {
if (map[c]) {
map[c]++;
} else {
map[c] = 1
}
}
for (c of s) {
if (map[c] === 1) {
return c
}
}
return ' '
};