Simple and clear python recursive solution

  • 1
    # 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:
                return None
            elif root.left and root.right:
       = root.right
                if if != None and we know that root.left and root.right != None, we should link and

Log in to reply

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