题解 | #字符流中第一个不重复的字符#
字符流中第一个不重复的字符
http://www.nowcoder.com/practice/00de97733b8e4f97a3fb5c680ee10720
# -*- coding:utf-8 -*-
class Solution:
def __init__(self):
self.d = dict()
self.a = []
# 返回对应char
def FirstAppearingOnce(self):
# write code here
for item in self.a:
if self.d.get(item) == 1:
return item
return "#"
def Insert(self, char):
# write code here
if self.d.get(char, 0) == 0:
self.d[char] = 1
else:
self.d[char] += 1
self.a.append(char)
class Solution:
def __init__(self):
self.d = dict()
self.a = []
# 返回对应char
def FirstAppearingOnce(self):
# write code here
for item in self.a:
if self.d.get(item) == 1:
return item
return "#"
def Insert(self, char):
# write code here
if self.d.get(char, 0) == 0:
self.d[char] = 1
else:
self.d[char] += 1
self.a.append(char)