Share Python Recursive solution

  • 0
    class Solution(object):
        def flat(self, root):
            if root == None: return None, None
            h1, t1 = self.flat(root.left)
            h2, t2 = self.flat(root.right)
            root.left = None
            tail = root
            if h1 != None:
                root.right = h1
                tail = t1
            if h2 != None:
                tail.right = h2
                tail = t2
            return root, tail
        def flatten(self, root):

Log in to reply

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