Clean Python 4 line O(1) space recursive solution


  • 0
    K
        def upsideDownBinaryTree(self, root):
            curr, temp, prev = root, None, None
            while curr:
                curr.right, curr.left, temp, curr, prev = prev, temp, curr.right, curr.left, curr
            return prev
    

Log in to reply
 

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