Python swaps in 4 lines


  • 1
    S
    class Solution(object):
        def upsideDownBinaryTree(self, root):
            prev = prev_right = None
            while root:
                root.right, root.left, prev_right, prev, root = prev, prev_right, root.right, root, root.left
            return prev

  • 0
    Z

    Thank you for sharing


Log in to reply
 

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