测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A18740. 以下函数可以正确完成二叉搜索树的插入,并保持二叉搜索树性质。class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def insertNode(root, x): if not root: return TreeNode(x) if x < root.val: root.rig…

判断题 困难

题目描述

以下函数可以正确完成二叉搜索树的插入,并保持二叉搜索树性质。

class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

def insertNode(root, x):
    if not root:
        return TreeNode(x)
    if x < root.val:
        root.right = insertNode(root.right, x)
    else:
        root.left = insertNode(root.left, x)
    return root

选项(单选)

上一题 下一题