原题是:
代码是:
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def invertTree(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
tmp = TreeNode(0)
if root == None:
return root
else :
tmp = root.left
root.left = root.right
root.right = tmp
self.invertTree(root.right)
self.invertTree(root.left)
return root