897. Increasing Order Search Tree
Last updated
Was this helpful?
Last updated
Was this helpful?
Given the root
of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child.
Example 1:
Constraints:
The number of nodes in the given tree will be in the range [1, 100]
.
0 <= Node.val <= 1000
Tree, Depth-first Search, Recursion
We initialize a dummy root node to store the output tree. We perform the in-order traverse on the input tree. For each visited node, we create a new node with the same value and assign it to the right-child of the rightmost node of the output tree. Finally, we return the right-child of the dummy root.
Time complexity:
Space complexity: