Linked List & Array | Striver’s SDE Sheet

Posted on Dec 25, 2020

Problem 1: Reverse a LinkedList

class Solution {
public:
    ListNode* reverseList(ListNode* next) {
        ListNode* prev = NULL;
        while(next != NULL)
        {
            ListNode* curr = next;
            next = next->next;
            curr->next = prev;
            prev = curr;
        }
        return prev;
    }
};