Invert Binary Tree
Given the root of a binary tree, invert the tree (mirror it left-to-right) and return its root. Every node's left and right subtrees are swapped.
Open official problem prompt ↗Produce the mirror image of a binary tree so that a left-to-right reflection of the original is returned.
Hold the tree up to a mirror: every branch that pointed left now points right and vice versa, all the way down.
- Input
- root = [4,2,7,1,3,6,9]
- Output
- [4,7,2,9,6,3,1]
- Why
- Each node keeps its value but its two subtrees swap places, mirroring the whole tree.
The number of nodes is in the range [0, 100]-100 <= Node.val <= 100