Invert Binary Tree
Part of Practice: Recursive Foundations
You are given the root of a binary tree. Flip the tree into its mirror image: for every node in the tree, its left child and right child swap places. Return the root of the flipped tree.
The tree can be empty, and has at most 100 nodes. Node values fit in a normal integer range and do not matter for the logic — only the structure changes.
Examples
- Input:
- root = [4,2,7,1,3,6,9]
- Output:
- [4,7,2,9,6,3,1]
Every left/right pair swaps: 2 and 7 trade places under 4, then their children trade places too.
- Input:
- root = [2,1,3]
- Output:
- [2,3,1]
- Input:
- root = []
- Output:
- []
An empty tree stays empty.
Hints
One at a time — struggle first, peek second.
Your thinking space — verify on LeetCode, then mark it.