python O(1) solution, no count


  • 0
    S
    class Solution:
        # @param root, a tree link node
        # @return nothing
        def connect(self, root):
            if not root:
                return
            leftfix = root
            while leftfix.left:
                uppermover = leftfix
                lowermover = TreeLinkNode(0)
                while uppermover:
                    lowermover.next = uppermover.left
                    lowermover = lowermover.next
                    lowermover.next = uppermover.right
                    lowermover = lowermover.next
                    uppermover = uppermover.next
                leftfix = leftfix.left
    
    

Log in to reply
 

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