my clear and easy understand python solution

  • 0
    class Solution:
        # @param root, a tree link node
        # @return nothing
        def connect(self, root):
            left = root
            cur = None
            while left:
                cur = left
                while cur:
                    if cur.left:
               = cur.right or self.find_next_node(
                    if cur.right:
               = self.find_next_node(
                    cur =
                left = self.find_next_node(left)
        def find_next_node(self, node):
            while node:
                if node.left:
                    return node.left
                if node.right:
                    return node.right
                node =
            return None

Log in to reply

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