998. 最大二叉树 II
Approach 1,递归
class Solution {
public TreeNode insertIntoMaxTree(TreeNode root, int val) {
if (root == null) {
return new TreeNode(val);
}
if (val > root.val) {
TreeNode cur = new TreeNode(val);
cur.left = root;
return cur;
}
root.right = insertIntoMaxTree(root.right, val);
return root;
}
}