题目描述
解法
计算每个字符出现的次数,并用一个dictionary存储。如果出现一次以上的value置为False,出现一次置为True,最后输出第一个为True的key。不存在则输出空
def firstUniqChar(self, s: str) -> str:
dic = {}
for char in s:
if char not in dic.keys():
dic[char] = True
else:
dic[char] = False
for key in dic.keys():
if dic[key] == True and key != '':
return key
return ' '