题解 | 字符流中第一个不重复的字符

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

https://www.nowcoder.com/practice/00de97733b8e4f97a3fb5c680ee10720

# -*- coding:utf-8 -*-
class Solution:
    # 返回对应char,字符串与存储字符串中字符计数的字典
    def __init__(self):
        self.s = ''
        self.dic = dict()
    def FirstAppearingOnce(self):#
        # write code here,输出第一个只出现1次的字符,无则输出#
        for c in self.s:
            if self.dic[c]==1:
                return c
        return '#'
    def Insert(self, char):
        # write code here,插入字符
        self.s += char
        self.dic[char] = self.dic.setdefault(char,0)+1

全部评论

相关推荐

不愿透露姓名的神秘牛友
03-19 10:38
实力求职者:真的绷不住了,第一张霸总人设,第二张求生欲拉满
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务