leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1047.cpp (419B)


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