Reversing a linked list using VECTORS


#1

Took my understanding deeper. Sharing a little different solution and one that can be easily understood if you have some grasp on vectors.

ListNode* Solution::reverseList(ListNode* A) {
    vector<ListNode*> B;
    while(A!=NULL){
        B.push_back(A);
        A=A->next;
    }
        
    for(int i=B.size()-1;i>=0;--i)
    {
        if(i-2>=0)
            B[i]->next = B[i-2]->next;
        if(i==1)
            B[1]->next = B[0];
        if(i==0)
            B[0]->next = NULL;
    }
    ListNode* temp1=B[B.size()-1];
    return temp1;
}

#2

Superb bro,I love your innovative