劍指向Offer-Python版 -- 字符流中第一個不重複的字符

題目描述

請實現一個函數用來找出字符流中第一個只出現一次的字符。例如,當從字符流中只讀出前兩個字符"go"時,第一個只出現一次的字符是"g"。當從該字符流中讀出前六個字符“google"時,第一個只出現一次的字符是"l"。

class Solution:
    # 返回對應char
    def FirstAppearingOnce(self):
        # write code here

    def Insert(self, char):
        # write code here
class Solution:

    def __init__(self):
        self.my_list = []

    def FirstAppearingOnce(self):
        for i in self.my_list:
            if self.my_list.count(i) == 1:
                return i
        return "#"

    def Insert(self, char):
        self.my_list.append(char)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章