LeetCode 206: Reverse Linked List – (Easy)

Given the head of a singly linked list, reverse the list, and return the reversed list.

Approach & Solution

We reverse a linked list by keeping track of two pointers: prev (the previous node) and curr (the current node). At each step,…


This content originally appeared on DEV Community and was authored by Grant Riordan

Given the head of a singly linked list, reverse the list, and return the reversed list.

example of reversal

Approach & Solution

We reverse a linked list by keeping track of two pointers: prev (the previous node) and curr (the current node). At each step, we:

  • Save the next node so we don’t lose track of the list.

  • Reverse the current node’s pointer to point to prev.

  • Move prev forward to curr.

  • Move curr forward to the saved next node.

We continue until curr is null, meaning we’ve processed all nodes. At that point, prev will be the new head of the reversed list.

Code

ListNode ReverseList(ListNode head)
{
ListNode prev = null;
ListNode curr = head;

while (curr != null)
{
    ListNode nextNode = curr.next;
    curr.next = prev;
    prev = curr;
    curr = nextNode;
}

return prev; // new head

}


This content originally appeared on DEV Community and was authored by Grant Riordan


Print Share Comment Cite Upload Translate Updates
APA

Grant Riordan | Sciencx (2025-09-16T13:37:28+00:00) LeetCode 206: Reverse Linked List – (Easy). Retrieved from https://www.scien.cx/2025/09/16/leetcode-206-reverse-linked-list-easy/

MLA
" » LeetCode 206: Reverse Linked List – (Easy)." Grant Riordan | Sciencx - Tuesday September 16, 2025, https://www.scien.cx/2025/09/16/leetcode-206-reverse-linked-list-easy/
HARVARD
Grant Riordan | Sciencx Tuesday September 16, 2025 » LeetCode 206: Reverse Linked List – (Easy)., viewed ,<https://www.scien.cx/2025/09/16/leetcode-206-reverse-linked-list-easy/>
VANCOUVER
Grant Riordan | Sciencx - » LeetCode 206: Reverse Linked List – (Easy). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/09/16/leetcode-206-reverse-linked-list-easy/
CHICAGO
" » LeetCode 206: Reverse Linked List – (Easy)." Grant Riordan | Sciencx - Accessed . https://www.scien.cx/2025/09/16/leetcode-206-reverse-linked-list-easy/
IEEE
" » LeetCode 206: Reverse Linked List – (Easy)." Grant Riordan | Sciencx [Online]. Available: https://www.scien.cx/2025/09/16/leetcode-206-reverse-linked-list-easy/. [Accessed: ]
rf:citation
» LeetCode 206: Reverse Linked List – (Easy) | Grant Riordan | Sciencx | https://www.scien.cx/2025/09/16/leetcode-206-reverse-linked-list-easy/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.