1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| class Solution { public: string removeDuplicates(string S) { stack<char>st; for(char s : S){ if(st.empty() || s != st.top())st.push(s); else{st.pop();} }
string result = ""; while(!st.empty()){ result += st.top(); st.pop(); } reverse(result.begin(), result.end()); return result; } };
|