题目:
解题思路:
设置一个变量temp用于记录括号的匹配:遇到“(”时temp+1;遇到“)”时temp-1。
代码实现(python版本):
class Solution:
def removeOuterParentheses(self, S: str) -> str:
temp=0
ss=""
for i in S:
if i=="(":
temp+=1
if temp>1:
ss+=i
else:
temp-=1
if temp!=0:
ss+=i
return ss