Recursive insert
Time O(h) Space O(h)insert(n): null → new node. Smaller → n.left = insert(n.left). Larger → n.right = insert(n.right). Return n.
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 root.right = insertIntoBST(root.right, val);
return root;
}
}Verdict: Short and clear.