Reverse Linked List (With Pointer)

PHOTO EMBED

Sun May 26 2024 13:44:10 GMT+0000 (Coordinated Universal Time)

Saved by @ayushg103 #c++

    ListNode* reverseList(ListNode* head)
    {ListNode* t1,*t2,*t3;
        t1 = head;
        if(head!=NULL)
         t2 = head->next;
        else
        return head;
        if(t2!=NULL)
        t3 = head->next->next;
        else
        {
            
            return head;
        }
        head->next=NULL;
        while(t3!=NULL)
        {
            t2->next=t1;
            t1=t2;
            t2=t3;
            t3=t3->next;
        }
        t2->next=t1;
        head = t2;
        return head;

    }
     
content_copyCOPY

its simple just think three nodes first change/reverse the link to 2->1 then just move forward