Concise python iterative solution using constant space


  • 0
    Y
    def connect(root):
        while root:
            next_head = root.left
            while root and root.left:
                root.left.next = root.right
                next_node = root.next
                if next_node:
                    root.right.next = next_node.left
                root = next_node
            root = next_head

Log in to reply
 

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