Simple python recursive implement


  • 0
    A
    class Solution(object):
        def flatten(self, root):
            """
            :type root: TreeNode
            :rtype: void Do not return anything, modify root in-place instead.
            """
            if root is None: return None
            self.flatten(root.right)
            if root.left: 
                self.flatten(root.left)
                right, root.right, root.left = root.right, root.left, None
                p = root.right
                while p and p.right: p = p.right
                p.right = right

Log in to reply
 

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