依旧是DFS搞定
class Solution:
def maxDepth(self, root: 'Node') -> int:
while root:
stack = [[1,root]]
max=1
while stack:
node = stack.pop()
if node[1].children:
for child in node[1].children:
depth = node[0]+1
stack.append([depth,child])
if depth>max:
max=depth
return max
return 0