天天看点

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

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

借助字典存储出现次数思想

# -*- coding:utf-8 -*-
class Solution:
    # 返回对应char
    def __init__(self):
        self.str_ = dict()
        self.result = []
    def FirstAppearingOnce(self):
        # write code here
        for i in self.result:
            if self.str_[i] == 1:
                return i
        return '#'
    def Insert(self, char):
        # write code here
        self.result.append(char)
        if char not in self.str_:
            self.str_[char] = 1
        else:
            self.str_[char] += 1
        
        
           

继续阅读