字符流中第一个不重复的字符

来源:互联网 发布:手机升温软件 编辑:程序博客网 时间:2024/05/18 16:36

题目描述

请实现一个函数用来找出字符流中第一个只出现一次的字符。例如,当从字符流中只读出前两个字符"go"时,第一个只出现一次的字符是"g"。当从该字符流中读出前六个字符“google"时,第一个只出现一次的字符是"l"。 
输出描述:
如果当前字符流没有存在出现一次的字符,返回#字符。

不知道后台测试代码是什么样子的,看着输出样例不知道什么意思,要表达什么

# -*- coding:utf-8 -*-class Solution:     s = ""    dt = {}    # 返回对应char    def FirstAppearingOnce(self):        # write code here        if self.dt is None:            return "#"        for x in self.s:            if self.dt[x] == 1:                return x        return "#"    def Insert(self, char):        # write code here        self.s += char        if char in self.dt:            self.dt[char] += 1        else:            self.dt[char] = 1


0 0
原创粉丝点击