Home Linked List I | Striver’s SDE Sheet
Post
Cancel

Linked List I | Striver’s SDE Sheet

Problem 1: Reverse a LinkedList

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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;
    }
};
This post is licensed under CC BY 4.0 by the author.

Array IV | Striver’s SDE Sheet

Linked List II | Striver’s SDE Sheet