Easy to understand Python 4 lines solution with comments:

  • 0
        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
            return root

Log in to reply

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