剑指向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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章