50. El primer carácter que aparece solo una vez (simple)

Descripción del Título:

在字符串 s 中找出第一个只出现一次的字符。如果没有,返回一个单空格。

示例:
s = "abaccdeff"
返回 "b"

s = "" 
返回 " "

Considere el uso de tablas hash:

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

 

Supongo que te gusta

Origin blog.csdn.net/weixin_38664232/article/details/104991185
Recomendado
Clasificación