美文网首页Leetcode
226. Invert Binary Tree

226. Invert Binary Tree

作者: oo上海 | 来源:发表于2016-08-02 08:45 被阅读14次

226. Invert Binary Tree

题目:
https://leetcode.com/problems/invert-binary-tree/

难度:

Easy


class Solution(object):
    def invertTree(self, root):
        """
        :type root: TreeNode
        :rtype: TreeNode
        """
        if root == None: return None
        elif root.left == None and root.right == None: return root
        else:
            leftNode = root.left
            rightNode = root.right
            root.right = leftNode
            root.left = rightNode
            self.invertTree(root.left)
            self.invertTree(root.right)
            return root

相关文章

网友评论

    本文标题:226. Invert Binary Tree

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