Invert Binary Tree
Given the root of a binary tree, invert it — swap the left and right child of *every* node — and return the new root.
Inverting is a mirror operation: the resulting tree is the reflection of the original across a vertical line through the root.
The tree is given as a level-order array where null marks a missing child: [2, 1, 3] is root 2 with children 1 and 3.
Example cases
- balancedin root = [4,2,7,1,3,6,9]1234679out [4,7,2,9,6,3,1]9764321Each node's children swap: 2↔7, 1↔3, 6↔9.
- smallin root = [2,1,3]123out [2,3,1]321
- emptyin root = []nullout []null
Constraints
- The number of nodes in the tree is in the range [0, 100].
- -100 <= Node.val <= 100
root =
[4,2,7,1,3,6,9]