My Python solution using recursion, 96ms runtime


  • 0
    S
    class Solution(object):
        def connect(self, root):
            """
            :type root: TreeLinkNode
            :rtype: nothing
            """
            if not root:
                return
            
            
            if root.left:
                root.left.next = root.right
                if root.next:
                    root.right.next = root.next.left
            
            self.connect(root.left)
            self.connect(root.right)

Log in to reply
 

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