[Search Algorithm (Binary Search)] Jianzhi Offer 50. The first character that appears only once

Problem Description :
Find the first character that appears only once in a string s. If not, return a single space. s contains only lowercase letters.

Example :
Input: s = "abaccdeff"
Output: 'b'

Solution : Use a hash table to solve it, but a hash set cannot solve it.

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

Guess you like

Origin blog.csdn.net/Rolandxxx/article/details/128938224