题解 | #字符流中第一个不重复的字符#
字符流中第一个不重复的字符
https://www.nowcoder.com/practice/00de97733b8e4f97a3fb5c680ee10720
#include <unordered_map> class Solution { public: unordered_map<char, int> m; string s; // 记录顺序,保证哈希访问顺序 //Insert one char from stringstream void Insert(char ch) { s+=ch; m[ch]++; } //return the first appearence once char in current stringstream char FirstAppearingOnce() { for(int i = 0; i < s.size(); ++i){ if(m[s[i]] == 1) { return s[i]; } } return '#'; } };
挤挤刷刷! 文章被收录于专栏
记录coding过程