先保留左子树为temp,左子树=右子树对本身函数的调用。右子树=temp对本身函数的调用。return root
def invertTree(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
if not root:
return root
temp = root.left
root.left = self.invertTree(root.right)
root.right = self.invertTree(temp)
return root