Untitled

mail@pastecode.io avatar
unknown
plain_text
11 days ago
552 B
2
Indexable
Never
class Solution {
public:
    string reverseParentheses(string s) {
        stack < int > st;
        
        for(int i=0;i<s.size();i++) {
            if(s[i] == ')') {
                reverse(s.begin() + st.top() + 1, s.begin() + i);
                st.pop();
            } else if(s[i]=='(') {
                st.push(i);
            }
        
        }
        
        string ans = "";
        
        for(int i=0;i<s.size();i++) {
            if(s[i] == ')' || s[i] == '(')continue;
            ans+=s[i];
        }
        return ans;
    }
};
Leave a Comment