Giving wrong answer please help


  • 0
    Y

    class Solution {

    private:

    TreeNode* ans= new TreeNode(-1);
    

    public:

    void dfs(TreeNode* root)
    {
        if(!root)
            return;
        insert(root);
        dfs(root->left);
        dfs(root->right);
    }
    void insert(TreeNode* x)
    {
        TreeNode* temp =ans;
        while(temp->right!=NULL)
            temp=temp->right;
        temp->right=x;
        temp=temp->right;
        temp->left=NULL;
        temp->right=NULL;
    }
    void flatten(TreeNode* root) 
    {
        dfs(root);
        root=ans->right;
        
    }
    

    };


Log in to reply
 

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