Swap the left and right child of every node in a binary tree and return the mirrored tree.
Given the root of a binary tree, create its mirror image by swapping the left and right child of every node in the tree.
You may return the modified tree root after in-place inversion, or a new root representing the inverted tree depending on your implementation style. The structure of the tree after inversion should be the same as if every node's children were exchanged recursively.
Example 1
Input
root = [4,2,7,1,3,6,9]
Output
[4,7,2,9,6,3,1]
Explanation
After inversion, every node's left and right children are swapped. The root stays the same, but its subtrees are mirrored.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.