Python iterative O(1) space solution (99%)

  • 0

    A real O(1) space solution. Easy to implement.
    Just need to utilize the "next" attribute.

    # Definition for binary tree with next pointer.
    # class TreeLinkNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    # = None
    class Solution:
        # @param root, a tree link node
        # @return nothing
        def connect(self, root):
            if not root:
            while cur.left:
                while temp:
           if else None

Log in to reply

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