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

2018-09-29  本文已影响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

暂略。

上一篇 下一篇

猜你喜欢

热点阅读