from collections import OrderedDict
class Solution:
# 返回对应char
def init(self):
# 初始化一个有序字典(里边的键全是只出现一次的)
self.doulist = []
self.array = OrderedDict()
def FirstAppearingOnce(self):
# write code here
if self.array:
for i in self.array:
return i
return '#'
def Insert(self, char):
# write code here
# 如果新字符已经存在字典中,就把字典中的该字符删掉
if char in self.array:
del self.array[char]
else:
# 如果新字符不存在与字典中,则添加到字典中
if char in self.doulist:
pass
else:
self.doulist.append(char)
self.array[char] = char
京公网安备 11010502036488号