
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def maxDepth(self, root):
"""
:type root: TreeNode
:rtype: int
"""
if root is None:
return 0
return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))
二叉树深度遍历解析
本文深入探讨了二叉树节点的定义及其最大深度的计算方法,通过递归算法实现,详细解释了如何确定一棵二叉树的深度,是理解二叉树结构和算法的重要参考资料。
658

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



