Python simple solution

  • 0
    class Solution:
        # @param root, a tree link node
        # @return nothing
        def connect(self, root):
            if not root: return root
            layer = [root]
            while layer:
                newlayer = []
                n0 = None
                for node in layer:
           = n0
                    n0 = node
                    if node.right:
                    if node.left:
                layer = newlayer

Log in to reply

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