第26857题 单选题
Python实现无重复值二叉排序树的插入函数,横线处应填入的正确代码是?
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

def insert(root, key):
    if root is None:
        return TreeNode(key)

    _________________________

    return root
A
if key < root.val:
    root.left = insert(root.left, key)
elif key > root.val:
    root.right = insert(root.right, key)
B
if key > root.val:
    root.left = insert(root.left, key)
elif key > root.val:
    root.right = insert(root.right, key)
C
if key < root.val:
    root.left = insert(root.left, key)
elif key >= root.val:
    root.right = insert(root.left, key)
D
if key < root.val:
    root.left = insert(root.right, key)
elif key > root.val:
    root.right = insert(root.left, key)
程序运行统计
暂无判题统计
提交0次 正确率0.00%
答案解析