python leetcode刷题 (29):559. N叉树的最大深度

题目描述:

python leetcode刷题 (29):559. N叉树的最大深度

解题过程:

递归能写出前几句啦,加油加油!

"""
# Definition for a Node.
class Node:
    def __init__(self, val, children):
        self.val = val
        self.children = children
"""
class Solution:
    def maxDepth(self, root: 'Node') -> int:
        if not root:
            return 0
        if not root.children:
            return 1
        
        result=0
        for c in root.children:
            result=max(result,self.maxDepth(c))
            
        return result+1

递归要注意整个函数末尾究竟return什么

总结:

None