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 ' '

猜你喜欢

转载自blog.csdn.net/weixin_38664232/article/details/104991185