leetcode

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

1190.cpp (526B)


      1 class Solution {
      2   public:
      3     string reverseParentheses(string s) const {
      4         stack<int> st;
      5         for (int i = 0; i < s.size(); i++) {
      6             if (s[i] == '(')
      7                 st.push(i);
      8             else if (s[i] == ')') {
      9                 reverse(begin(s) + st.top(), begin(s) + i);
     10                 st.pop();
     11             }
     12         }
     13 
     14         int size = 0;
     15         for (int i = 0; i < s.size(); i++)
     16             if (s[i] != '(' && s[i] != ')') s[size++] = s[i];
     17         s.resize(size);
     18 
     19         return s;
     20     }
     21 };