Skip to content

Instantly share code, notes, and snippets.

@shafiul
Created September 16, 2019 15:54
Show Gist options
  • Save shafiul/a2dc136a86dcc7e587426f40739caad9 to your computer and use it in GitHub Desktop.
Save shafiul/a2dc136a86dcc7e587426f40739caad9 to your computer and use it in GitHub Desktop.
class Solution {
public:
string reverseParentheses(string s) {
deque<stringstream> stk;
stk.push_back(stringstream());
for(auto const & c : s){
if(c == '('){
stk.push_back(stringstream());
}else if(c == ')'){
auto top = stk.back().str(); stk.pop_back();
reverse(top.begin(), top.end());
stk.back() << top;
}else{
stk.back() << c;
}
}
return stk.back().str();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment