题解 | #字符流中第一个不重复的字符#
字符流中第一个不重复的字符
https://www.nowcoder.com/practice/00de97733b8e4f97a3fb5c680ee10720
class Solution
{
public:
vector<char> v;
unordered_map<char, int> hash;
//Insert one char from stringstream
void Insert(char ch) {
v.push_back(ch);
hash[ch]++;
}
//return the first appearence once char in current stringstream
char FirstAppearingOnce() {
for (auto &i: v) if (hash[i] == 1) return i;
return '#';
}
};

查看15道真题和解析