字符串 s 中找出第一个只出现一次的字符。如果没有,返回一个单空格。 s 只包含小写字母。
示例 1:
输入:s = "abaccdeff" 输出:'b'
示例 2:
python3实现输入:s = "" 输出:' '
编码思路: 切片法(python独有),也可以用hash map
class Solution:
def firstUniqChar(self, s: str) -> str:
rs = " "
for i in range(len(s)):
if s[i] not in s[:i] and s[i] not in s[i+1:]:
return s[i]
return rs
c++实现
编码思想:使用哈希表存储频数
class Solution {
public:
char firstUniqChar(string s) {
unordered_map freq;
for(char c:s){
++freq[c];
}
for(int i=0; i 


