ReverseTree

Reverse the Tree

Solution: reverse by threes similair to reverse linked list in pairs

For 4 6 7 subproblem(last subproblem)

6 is new root

6.left = 4

6.right = 7

Node

Action Taken

6 is new root

newRoot = reverseTree(6) = 6

4 is new left

root.left.left = root

7 is new right

root.left.right = root.right

4.left is assigned later by 2

root.left = null

4.right is assigned

root.right = null

Last updated

Was this helpful?