Simple to understand Python solution using traversal


  • 0
    N

    I though of this problem as doing postorder traversal.

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

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.