递归不解释
class Solution:
"""
@param root: The root of binary tree.
@return: An integer
"""
def maxDepth(self, root):
# write your code here
if root == None:
return 0
lh = self.maxDepth(root.left)
rh = self.maxDepth(root.right)
return max(lh,rh)+1
本文介绍了一种递归算法来计算二叉树的最大深度。通过不断递归左右子树并比较其深度,最终得出整棵树的最大深度。
1073

被折叠的 条评论
为什么被折叠?



