Invert Binary Tree
Problem statement
Given the root of a binary tree, invert the tree by swapping the left and right child of every node. Return the root of the inverted tree.
Function
invertTree(root: TreeNode) → TreeNodeExamples
Example 1
root = [4,2,7,1,3,6,9]return = [4,7,2,9,6,3,1]Every node's two child links are swapped.
Example 2
root = []return = []An empty tree remains empty.
Constraints
- The tree contains between
0and10^5nodes. -10^9 <= Node.val <= 10^9.