Reverse Linked List | Problem No. 206 | LeetCode

Subscribe to my newsletter and never miss my upcoming articles

Reverse a singly linked list.

Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL Solution:

Approach 1: Recursive

    ListNode* reverseList(ListNode* head) {
        if(head==NULL || head->next==NULL)
            return head;
        ListNode* prev = reverseList(head->next);
        head->next->next=head;
        head->next=NULL;
        return prev;
    }

No Comments Yet