fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class Solution {
  5. public:
  6. string removeDuplicates(string s) {
  7. stack<char>st;
  8. for (auto &c : s) {
  9. if (!st.empty() && c == st.top()) {
  10. st.pop();
  11. }
  12. else {
  13. st.push(c);
  14. }
  15. }
  16.  
  17. ostringstream ss;
  18. while (!st.empty()) {
  19. ss << st.top();
  20. st.pop();
  21. }
  22. string res = ss.str();
  23. reverse(res.begin(), res.end());
  24. return res;
  25. }
  26. };
  27.  
  28. int main() {
  29. // your code goes here
  30. return 0;
  31. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Standard output is empty