题目浅析

  • 想查看原题可以点击题目链接

  • 简单地说,就是给一个字符串,对于其中所有括号包裹的部分做反转操作,同时去掉括号,求最终处理后的字符串

思路分享

代码解答(强烈建议自行解答后再看)

  • 参考题解
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution:
def reverseParentheses(self, s: str) -> str:
stk = list()
for c in s:
if c == ')':
tmp_c = stk.pop()
tmp_stk = list()
while tmp_c != '(':
tmp_stk.append(tmp_c)
tmp_c = stk.pop()
stk.extend(tmp_stk)
else:
stk.append(c)
# print(stk)
return "".join(stk)