52 ms python solution


  • 0
    R
    def flatten(self, root):
        """
        :type root: TreeNode
        :rtype: void Do not return anything, modify root in-place instead.
        """
        if not root:
            return
        right = root.right
        if root.left:
            self.flatten(root.left)
            leaf = root.left
            while leaf.right:
                leaf = leaf.right
            root.right, root.left, leaf.right = root.left, None, root.right
        
        self.flatten(right)

Log in to reply
 

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