美文网首页
32.LeetCode559. N叉树的最大深度.

32.LeetCode559. N叉树的最大深度.

作者: 月牙眼的楼下小黑 | 来源:发表于2018-09-29 15:44 被阅读42次
    • 标签: 深度优先搜索 广度优先搜索
    • 难度: 简单

    • 题目描述
    • 我的解法: 递归
    """
    # Definition for a Node.
    class Node(object):
        def __init__(self, val, children):
            self.val = val
            self.children = children
    """
    class Solution(object):
        def maxDepth(self, root):
            """
            :type root: Node
            :rtype: int
            """
            subtrees_maxDepth = []
            if not root:
                return 0
            if(not root.children):
                return 1
            for child in root.children:
                subtrees_maxDepth.append(self.maxDepth(child))
            return max(subtrees_maxDepth) + 1
    
    • 其他解法

    暂略。

    相关文章

      网友评论

          本文标题:32.LeetCode559. N叉树的最大深度.

          本文链接:https://www.haomeiwen.com/subject/szqboftx.html