01 · Question
Given the root of a binary tree, invert the tree, and return its root.
02 · Solution
1def invertTree(root: Optional[TreeNode]) -> Optional[TreeNode]:2 if not root:3 return None4 root.left, root.right = root.right, root.left5 invertTree(root.left)6 invertTree(root.right)7 return root