Last updated 2 years ago
string removeDuplicates(string s) { stack<char> st; for(char ch: s) if(!st.empty() && st.top() == ch) st.pop(); else st.push(ch); string res = ""; while(!st.empty()) { res += st.top(); st.pop(); } reverse(res.begin(), res.end()); return res; }