Linked List· 15 min
Reverse Linked List
LeetCode #206 · Easy · Interactive step-by-step visualization
Setup
Example input
head = [1, 2, 3, 4, 5]Step 1 / 17
Current step
1 / 17Reverse the links, not the values. Each node keeps its value; only the direction of every pointer changes. Track previous, current and the next node before any link is cut.
Step log
head
headnull
1
2
3
4
5
list
1 → 2 → 3 → 4 → 5
Named pointer
Active node
Committed or completed
Detached or removed
reverse-linked-list.java
1public ListNode reverseList(ListNode head) {2 ListNode prev = null, curr = head;3 while (curr != null) {4 ListNode next = curr.next;5 curr.next = prev;6 prev = curr;7 curr = next;8 }9 return prev;10}● Java
Time
O(n)
Space
O(1)
Pattern
linked list
Frames
17
