> For the complete documentation index, see [llms.txt](https://llssff.gitbook.io/coding-problems/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://llssff.gitbook.io/coding-problems/recusion/reversetree.md).

# ReverseTree

Reverse the Tree

![](https://1509805518-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MNkNlNl5fRVReS8KLNV%2F-MQislycrQ2G20mozElP%2F-MQj74Qy-hljgSK4gfgg%2FCapture.PNG?alt=media\&token=098eb035-7d67-4058-928a-3c011ea7ceee)

**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   &#x20;

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            |
