题解 | #字符流中第一个不重复的字符#
字符流中第一个不重复的字符
https://www.nowcoder.com/practice/00de97733b8e4f97a3fb5c680ee10720
class Solution
{
public:
//Insert one char from stringstream
void Insert(char ch) {
counts[ch]++;
que.push(ch);
while (!que.empty() && counts[que.front()] > 1) {
que.pop();
}
}
//return the first appearence once char in current stringstream
char FirstAppearingOnce() {
if (que.empty()) {
return '#';
}
return que.front();
}
private:
vector<int> counts = vector<int>(128, 0); // 牛客c++版本较低,应该这样初始化
queue<char> que;
};
华为HUAWEI工作强度 1383人发布