一、1021. 删除最外层的括号
1.1、题目描述
class Solution:
def removeOuterParentheses(self, S: str) -> str:
stk = [] # 使用列表模拟栈
count = 0
s = ''
for c in S:
if c == '(': # 左括号入栈
stk.append(c)
count += 1
if count > 1:
s += c
else: # 右括号出站
stk.pop()
if count > 1:
s += c
count -= 1
return s