No extra space, 6 lines simple solution in python


  • 1
    class Solution(object):
        def connect(self, root):
            if not (root and root.left):
                return
    
            root.left.next = root.right
            if root.next:
                root.right.next = root.next.left
    
            map(self.connect, (root.left, root.right))

Log in to reply
 

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