/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public TreeNode insertIntoBST(TreeNode root, int val) {
if(root==null){
return new TreeNode(val);
}
if(val<root.val){
root.left=insertIntoBST(root.left,val);
}else if(val>root.val){
root.right=insertIntoBST(root.right,val);
}
return root;
}
}
二分搜索树-二叉搜索树中的插入(领扣)
最新推荐文章于 2022-04-27 20:05:29 发布