Maximum Binary Tree II LeetCode solution in Java

1
class Solution {
2
public TreeNode insertIntoMaxTree(TreeNode root, int val) {
3
if (root == null) return new TreeNode(val);
4
if (val > root.val) {
5
TreeNode newRoot = new TreeNode(val);
6
newRoot.left = root;
7
return newRoot;
8
}
9
root.right = insertIntoMaxTree(root.right, val);
10
return root;
11
}
12
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0