Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::string reverseParentheses(std::string s) {
- std::stack<std::string> str;
- str.push(std::string());
- for (char c : s) {
- if (c == '(')
- str.push(std::string());
- else if (c == ')') {
- std::string newS = str.top();
- std::reverse(newS.begin(), newS.end());
- str.pop();
- str.top() += newS;
- }
- else
- str.top() += c;
- }
- return str.top();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement