June 11, 2022 · 1 min read
https://www.geeksforgeeks.org/reverse-a-linked-list/
class Solution {
public:
struct Node *reverseList(struct Node *head) {
if (head == nullptr)
return head;
Node *prev = nullptr, *next, *curr = head;
while (curr != nullptr) {
next = curr->next;
curr->next = prev;
prev = curr;
curr = next;
}
return prev;
}
};