Python swaps in 4 lines

  • 1
    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

    Thank you for sharing

Log in to reply

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