206. Reverse Linked List
Date: 2026-03-16 Difficulty: Easy Topics: Linked List, Recursion Link: https://leetcode.com/problems/reverse-linked-list/
Final Solution
class Solution:
def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
if not head or not head.next:
return head
newHead = self.reverseList(head.next)
head.next.next = head
head.next = None
return newHeadInitial Issues
- Struggled significantly with the recursive approach
- Specifically confused by the pointer manipulation:
head.next.next = headandhead.next = None - Hard to visualize what’s happening as recursion unwinds
Key Learnings
- The recursive solution works by recursing to the end of the list first, then reversing pointers on the way back up the call stack
newHeadis always the last node (found at base case) and gets passed all the way back unchanged- The key insight: when recursion unwinds at node
head,head.nextstill points to the next node. Sohead.next.next = headmakes that next node point back tohead(reversing the link) head.next = Nonebreaks the old forward link to avoid cycles
Nuances to Remember
- Walk through example:
1->2->3->None- Base case returns
3asnewHead - At
head=2:head.nextis3, so3.next = 2(now3->2), then2.next = None - At
head=1:head.nextis2, so2.next = 1(now2->1), then1.next = None - Result:
3->2->1->None,newHeadis still3
- Base case returns
- The iterative approach (prev/curr/next pointers) is more intuitive but recursive is important to understand for interview follow-ups
head.next.nextis NOT double-jumping — it’s accessing thenextpointer OF the node thathead.nextpoints to