美文网首页
[easy][Tree]226.Invert Binary Tr

[easy][Tree]226.Invert Binary Tr

作者: 小双2510 | 来源:发表于2017-11-06 04:17 被阅读0次

    原题是:

    Screen Shot 2017-11-05 at 3.17.19 PM.png

    代码是:

    # 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
    

    相关文章

      网友评论

          本文标题:[easy][Tree]226.Invert Binary Tr

          本文链接:https://www.haomeiwen.com/subject/leskmxtx.html