用递归法做的
"""
# Definition for a Node.
class Node:
def __init__(self, val=None, children=None):
self.val = val
self.children = children
"""
class Solution:
def maxDepth(self, root: 'Node') -> int:
if root:
depth = 0
for i in range(len(root.children)):
depth = max(depth,self.maxDepth(root.children[i]))
return depth +1
else:
return 0