Mirror a Binary Tree
Problem statement
Return the mirror image of the binary tree by swapping the left and right children at every node. Preserve every node value. You may modify the input tree in place. An empty tree remains empty.
Function
mirrorTree(root: TreeNode) → TreeNodeExamples
Example 1
root = [4,2,7,1,3,6,9]return = [4,7,2,9,6,3,1]The root children become7 and2; the next level becomes9,6,3,1.
Example 2
root = [1,2,null,3]return = [1,null,2,null,3]Every left-only edge becomes a right-only edge.
Constraints
0 <= serialized tree length <= 400.-1000 <= every non-null node value <= 1000.- The input is a valid acyclic binary tree serialized level by level, with null for a missing child; [] denotes an empty tree.