【查找算法(二分查找)】剑指 Offer 50. 第一个只出现一次的字符

题目描述
在字符串 s 中找出第一个只出现一次的字符。如果没有,返回一个单空格。 s 只包含小写字母。

示例
输入:s = “abaccdeff”
输出:‘b’

题解:运用哈希表来解决,哈希集合解决不了。

class Solution:
    def firstUniqChar(self, s: str) -> str:
        dic = {
    
    }
        for i in s:
            if i in dic:
                dic[i] = False
            else:
                dic[i] = True
        for i in s:
            if dic[i]:
                return i
        return " "

猜你喜欢

转载自blog.csdn.net/Rolandxxx/article/details/128938224