simple dfs python solution


  • 5
    G

    '''

    def flatten(self, root):
        last=TreeNode(-1)
        qstack=[root]
        while qstack:
            node=qstack.pop()
            last.right=node
            last.left=None
            if node and node.right:
                qstack.append(node.right)
            if node and node.left:
                qstack.append(node.left)
            last=node
        '''

Log in to reply
 

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