← Back to DSA Animator
Reverse Linked List LC #206 Easy Linked List · In-place
Problem

Given the head of a singly linked list, reverse the list, and return the reversed list. Do it in-place with O(1) extra space.

Example 1
Input: head = [1,2,3,4,5]
Output: [5,4,3,2,1]
Example 2
Input: head = [1,2]
Output: [2,1]
Constraints: 0 ≤ n ≤ 5000  |  −5000 ≤ Node.val ≤ 5000
Try Examples
Custom:
Linked List
List reversed — new head =
Pointer State
prev
null
curr
nxt
Step Logic
Press ▶ Play or Next Step to begin the animation.
🎉
Ready
0 / 0
Select an example above and press Play.
Algorithm
1
Init prev = null, curr = head
2
Loop while curr != null
3
Save nxt = curr.next (don't lose the rest of the list)
4
Flip pointer: curr.next = prev
5
Advance: prev = curr, curr = nxt
6
Return prev — the new head of the reversed list
Time
O(n)
Space
O(1)
Why It Works

At every step, everything behind curr is already a valid reversed sub-list whose new head is prev. By saving nxt before clobbering curr.next, we never lose the forward chain. When curr reaches null, the entire list has been reversed and prev points to the new head.