def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
head = root
def _invert_tree(node):
if not node:
return
node.left, node.right = node.right, node.left
_invert_tree(node.left)
_invert_tree(node.right)
_invert_tree(root)
return head