classSolution { public: //Insert one char from stringstream int pos[256]{0}; int len = 0; voidInsert(char ch) { if (pos[ch] == 0) { pos[ch] = len + 1; } else { pos[ch] = -1; } len++; } //return the first appearence once char in current stringstream charFirstAppearingOnce() { char t = '#'; int min_pos = 0; for (int i = 0; i < 256; i++) { int current_pos = pos[i]; if (current_pos > 0) { if (min_pos == 0 || min_pos > current_pos) { min_pos = current_pos; t = i; } } } return t; } };