题解 | 字符流中第一个不重复的字符
字符流中第一个不重复的字符
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
查看8道真题和解析
