50. 第一個只出現一次的字符(簡單)

題目描述:

在字符串 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 ' '

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章