''' 題目描述 請實現一個函數用來找出字符流中第一個只出現一次的字符。 例如,當從字符流中只讀出前兩個字符"go"時,第一個只出現一次的字符是"g"。 當從該字符流中讀出前六個字符“google"時,第一個只出現一次的字符是"l"。 ''' # -*- coding:utf-8 -*- class Solution: # 返回對應char def __init__(self): self.str='' self.count=[0 for _ in range(256)] def FirstAppearingOnce(self): # write code here for i in self.str: if self.count[ord(i)]==1: return i return '#' def Insert(self, char): # write code here self.str+=char self.count[ord(char)]+=1
python 字符流中第一個不重複的字符
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
python3 super 用法2
class MetaCls(type): def __new__(cls, *args, **kwargs): print("in MetaCls") # return super(Meta