2019年4月8日 1021. Remove Outermost Parentheses

class Solution(object):
    def removeOuterParentheses(self, S):
        """
        :type S: str
        :rtype: str
        """
        mark = 0
        ret = ''
        for i in S:
            if i == '(':
                if mark == 0:
                    mark = 1
                    continue
                mark += 1
            elif i == ')':
                mark -= 1
                        
            if mark > 0:
                ret += i
                
        return ret
posted @ 2019-04-08 09:25  miuc  阅读(159)  评论(0编辑  收藏  举报