-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1190.cpp
More file actions
31 lines (30 loc) · 762 Bytes
/
1190.cpp
File metadata and controls
31 lines (30 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Solution {
public:
string _reverse(string& s, int& index, bool isReverse) {
string out = "";
int n = s.size();
while (index < n) {
if (s[index] == ')') {
index++;
break;
}
else if (s[index] == '(') {
index++;
string append = _reverse(s, index, true);
out += append;
}
else {
out.push_back(s[index]);
index++;
}
}
if (isReverse) {
reverse(out.begin(), out.end());
}
return out;
}
string reverseParentheses(string s) {
int index = 0;
return _reverse(s, index, false);
}
};