C# Reverse Pre Order - Accepted


  • 0
    S
    TreeNode prevNode = null;
    
    // Reverse Pre Order technique. Go right first and start building list from back to front.
    public void Flatten(TreeNode node) 
    {
        if(node == null)
            return;
    
        Flatten(node.right);
        Flatten(node.left);
        
        node.right = prevNode;
        node.left = null;
        prevNode = node;
    }

Log in to reply
 

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