第14459题 单选
下列关于求解二叉树深度的Python代码的说法中,不正确的是?
def getDepth(root):
    if root is None:
        return 0
    left_depth = getDepth(root.left)
    right_depth = getDepth(root.right)
    if left_depth < right_depth:
        return right_depth + 1
    else:
        return left_depth + 1
A

该代码可用于求解二叉树的深度

B

代码中函数getDepth()的参数root表示根节点,非根节点不可以作为参数

C

代码中函数getDepth()采用了递归方法

D

代码中函数getDepth()可用于求解各种形式的二叉树深度,要求该二叉树节点至少有left和right属性

提交0次 正确率0.00%
答案解析