Skip to content

Commit df8939f

Browse files
committed
2019-09-14
1 parent 540a28d commit df8939f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution(object):
2+
def reverseParentheses(self, s):
3+
"""
4+
:type s: str
5+
:rtype: str
6+
"""
7+
if not s or ")" not in s:
8+
return s
9+
stack = []
10+
for i, char in enumerate(s):
11+
if char == "(":
12+
stack.append(i)
13+
elif char == ")":
14+
left = stack.pop()
15+
right = i
16+
return self.reverseParentheses(s[:left] + s[left + 1:right][::-1] + s[right + 1:])
17+

0 commit comments

Comments
 (0)