We are given the
root node of a maximum tree: a tree where every node has a value greater than any other value in its subtree.
Just as in the previous problem, the given tree was constructed from an list
root = Construct(A)) recursively with the following
Ais empty, return
A[i]be the largest element of
A. Create a
rootnode with value
Construct([A, A, ..., A[i-1]])
Construct([A[i+1], A[i+2], ..., A[A.length - 1]])
Note that we were not given A directly, only a root node
root = Construct(A).
B is a copy of
A with the value
val appended to it. It is guaranteed that
B has unique values.
Input: root = [4,1,3,null,null,2], val = 5 Output: [5,4,null,1,3,null,null,2] Explanation: A = [1,4,2,3], B = [1,4,2,3,5]
Input: root = [5,2,4,null,1], val = 3 Output: [5,2,4,null,1,null,3] Explanation: A = [2,1,5,4], B = [2,1,5,4,3]
Input: root = [5,2,3,null,1], val = 4 Output: [5,2,4,null,1,3] Explanation: A = [2,1,5,3], B = [2,1,5,3,4]
1 <= B.length <= 100