首页 > 其他 > 详细

1111. 有效括号的嵌套深度

时间:2020-06-08 14:21:59      阅读:43      评论:0      收藏:0      [点我收藏+]

技术分享图片
技术分享图片
技术分享图片
技术分享图片
技术分享图片

class Solution(object):
    def maxDepthAfterSplit(self, seq):
        """
        :type seq: str
        :rtype: List[int]
        """
        res = []
        if not seq:
            return res
        depth, max_depth = 0, 0
        for ch in seq:
            if ch == "(":
                depth += 1
                if depth > max_depth:
                    max_depth = depth
            else:
                depth -= 1
        a_depth = 0
        mid = 1 + (max_depth-1)//2
        for ch in seq:
            if ch == "(":
                if a_depth < mid:
                    res.append(0)
                    a_depth += 1
                else:
                    res.append(1)
            else:
                if a_depth > 0:
                    res.append(0)
                    a_depth -= 1
                else:
                    res.append(1)
        return res

if __name__ == ‘__main__‘:
    solution = Solution()
    print(solution.maxDepthAfterSplit(seq="(()())"))

1111. 有效括号的嵌套深度

原文:https://www.cnblogs.com/panweiwei/p/13065301.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!