Gowthaman Ravi
Gowthy's Blog

Gowthy's Blog

Reverse Linked List | Problem No. 206 | LeetCode

Gowthaman Ravi's photo
Gowthaman Ravi
·Feb 1, 2021·

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);
        return prev;
Share this