50. The first face questions of character appears only once

Find the string s in the first character appears only once. If not, return to a single space.

Example:

s = "abaccdeff"
返回 "b"

s = "" 
返回 " "

You can utilize python dictionary.

 

class Solution:
    def firstUniqChar(self, s: str) -> str:
        numdic = dict()
        for c in s:
            if c in numdic:
                numdic[c] += 1
            else:
                numdic[c] = 1
        
        for i in numdic:
            if numdic[i] == 1:
                return i
        return " "

 

Published 385 original articles · won praise 210 · views 520 000 +

Guess you like

Origin blog.csdn.net/qq_32146369/article/details/104501325