leetcode559 Python3 128ms N叉树的最大深度

Posted 一条图图犬

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode559 Python3 128ms N叉树的最大深度相关的知识,希望对你有一定的参考价值。

"""
# 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
        """
        if not root:
            return 0
        if not root.children:
            return 1
        return 1 + max(list(map(self.maxDepth, root.children)))
        

以上是关于leetcode559 Python3 128ms N叉树的最大深度的主要内容,如果未能解决你的问题,请参考以下文章