題目描述:
在字符串 s 中找出第一個只出現一次的字符。如果沒有,返回一個單空格。
示例:
s = "abaccdeff"
返回 "b"
s = ""
返回 " "
考察哈希表的用法:
class Solution(object):
def firstUniqChar(self, s):
"""
:type s: str
:rtype: str
"""
hash_dic={}
for i in s:
hash_dic[i]=hash_dic.get(i,0)+1
for c in s:
if hash_dic[c]==1:
return c
return ' '