请实现一个函数用来找出字符流中第一个只出现一次的字符。例如,当从字符流中只读出前两个字符"go"时,第一个只出现一次的字符是"g"。当从该字符流中读出前六个字符“google"时,第一个只出现一次的字符是"l"。python
输出描述:数组
若是当前字符流没有存在出现一次的字符,返回#字符。函数
时间限制:1秒;空间限制:32768K;本题知识点:字符串google
用一个足够大的数组来记录对应ascii码值的字符出现的次数,再判断字符流中第一个不重复的字符。code
Python代码:utf-8
# -*- coding:utf-8 -*- class Solution: # 返回对应char def __init__(self): self.s = [0]*256 #ascii码表记录出现次数 self.l='' #记录输入字符流 def FirstAppearingOnce(self): # write code here for i in self.l: if self.s[ord(i)] == 1: #仅出现一次 return i return '#' def Insert(self, char): # write code here self.l = self.l + char self.s[ord(char)] += 1