diff --git a/1190. Reverse Substrings Between Each Pair of Parentheses b/1190. Reverse Substrings Between Each Pair of Parentheses new file mode 100644 index 0000000..477eb5e --- /dev/null +++ b/1190. Reverse Substrings Between Each Pair of Parentheses @@ -0,0 +1,31 @@ +class Solution { +public: + void reverseString(string &s, int i, int j) + { + while(i < j) + { + if(s[i] == '(') i++; + if(s[j] == ')') j--; + swap(s[i++], s[j--]); + } + } + string reverseParentheses(string s) + { + stackst; + int n = s.size(); + for(int i = 0; i < n; i++) + { + if(s[i] == '(') st.push(i); + if(s[i] == ')') + { + reverseString(s, st.top(), i); + st.pop(); + } + } + + string ans; + for(auto ch:s) + if(isalpha(ch)) ans += ch; + return ans; + } +};