```
class Solution(object):
def invertTree(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
if not root:
return root
pre = root
queue = [pre]
while queue:
current = queue.pop()
if current.left:
queue.append(current.left)
if current.right:
queue.append(current.right)
current.left, current.right = current.right, current.left
return pre
```