下列函数试图把整数 x 插入二叉搜索树(左子树值都小于结点、右子树值都不小于结点)。判断它能否在插入后保持二叉搜索树性质。
TreeNode* insertNode(TreeNode* root, int x) {
if (root == nullptr) return new TreeNode(x);
if (x < root->val) {
root->right = insertNode(root->right, x); // 方向写反
} else {
root->left = insertNode(root->left, x); // 方向写反
}
return root;
}
正确答案:错误(×)