Open youngyangyang04 opened 3 months ago
class Solution {
public TreeNode insertIntoBST(TreeNode node, int val) {
if (node == null) return new TreeNode(val);
if (val < node.val){
node.left = insertIntoBST(node.left, val);
} else if (node.val < val){
node.right = insertIntoBST(node.right, val);
}
return node;
}
}
https://www.programmercarl.com/0701.%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E4%B8%AD%E7%9A%84%E6%8F%92%E5%85%A5%E6%93%8D%E4%BD%9C.html