在字符串 s 中找出第一个只出现一次的字符。如果没有,返回一个单空格。 s 只包含小写字母。
const firstUniqChar = str => {
if (!str) return ' ';
const m = new Map();
for (const s of str) {
m.set(s, (m.get(s) || 0) + 1);
}
for (const s of m) {
if (s[1] === 1) return s[0];
}
return ' ';
};