206. Reverse Linked List¶
Edited by Charles
Easy · Python · LinkedList
Problem
Read the original problem on LeetCode.
The official page contains the problem statement, examples, and constraints.
Explanation, examples & other approaches
Core idea
Main logic:
Define two pointers: previous and current. Current points to the head and previous points to None.
Original study notes follow, including intermediate snippets and earlier attempts.
Main logic:
- Define two pointers: previous and current.
- Current points to the head and previous points to None.
- Iterate the whole linked list:
- define temp to save current.next, since we need current to move forward after making the current node point to the previous.
- let current.next be previous (reversion is done)
- let previous be current (move both previous and current)
- let current be temp
Study record
| Field | Value |
|---|---|
| Attempts | 3 |
| Mastery | ❚❚❚ |
| The Latest Attempt | January 4, 2026 |
Python solution¶
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
current = head
previous = None
while current:
temp = current.next
current.next = previous
previous = current
current = temp
return previous