第31726题 单选题
现有Python实现的递归求解二叉树最大深度的代码,横线处应填入的正确语句是?
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

def max_depth(root: TreeNode) -> int:
    # 递归终止条件:空节点深度为0
    if not root:
        return 0
    # 待填写逻辑
    ________
A

return 1 + max(max_depth(root.left), max_depth(root.right))

B

return max(max_depth(root.left), max_depth(root.right))

C

return 1 + max_depth(root.left) + max_depth(root.right)

D

return 1 + min(max_depth(root.left), max_depth(root.right))

程序运行统计
暂无判题统计
提交0次 正确率0.00%
答案解析