class Solution(object):
def removeOuterParentheses(self, S):
"""
:type S: str
:rtype: str
"""
res, opened = [], 0
for c in S:
if c == '(' and opened > 0:
res.append(c)
if c == ')' and opened > 1:
res.append(c)
opened += 1 if c =='(' else -1
return "".join(res)
除掉最外层的括号就是剩下的答案