-
标签:
树
深度优先搜索
广度优先搜索
-
难度:
简单
- 题目描述
- 我的解法: 递归
"""
# 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
- 其他解法
暂略。
网友评论