```
class Solution(object):
def invertTree(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
level = [root] if root else []
while level:
q = []
for node in level:
if node.left:
q.append(node.left)
if node.right:
q.append(node.right)
node.left, node.right = node.right, node.left
level = q
return root
```

:levitate: