My solution C++ 6ms


  • 0
    T
    TreeNode* global1 = (TreeNode *) malloc(sizeof(TreeNode));
    void flat(TreeNode *A)
    {
        if(A==NULL)
            return;
        global1->right = A;
        TreeNode *left = A->left;
        TreeNode *right = A->right;
    
        global1->left = NULL;
        global1 = global1->right;
    
        flat(left);
        flat(right);
    
        return;
    
    }
    void flatten(TreeNode* A) {
        TreeNode *save = global1;
        flat(A);
            A = save;
        
    }
    

    };


Log in to reply
 

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