leetcode Invert Binary Tree python

# 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
        """
        if root is None:
            return None
        if root.left:
            self.invertTree(root.left)
        if root.right:
            self.invertTree(root.right)
        root.left,root.right=root.right,root.left
        return root

 

posted @ 2015-12-06 14:58  hao.ma  阅读(201)  评论(0编辑  收藏  举报