Easy to understand Python 4 lines solution with comments:


  • 0
    S
        def invertTree(self, root):
            if not root: return root
            # Invert the left and right of current tree
            root.left, root.right = root.right, root.left
            # Recursively invert left and right sub trees
            self.invertTree(root.left)
            self.invertTree(root.right)
            return root

Log in to reply
 

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