A relative concise Python code


  • 1
    P
    class Solution:
        # @param root, a tree link node
        # @return nothing
        def connect(self, root):
            if not root:
                return
            self.connect(root.left)
            self.connect(root.right)
            p, q = root.left, root.right
            while p:
                p.next = q
                p = p.right
                q = q.left

Log in to reply
 

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