← Back to DSA Animator
Palindrome Linked List LC #234 Easy Linked List · Two Pointers · Reverse
Problem

Given the head of a singly linked list, return true if it is a palindrome, or false otherwise.

Example 1
Input: head = [1,2,2,1]
Output: true
Example 2
Input: head = [1,2]
Output: false
Constraints: 1 ≤ n ≤ 10⁵  |  0 ≤ Node.val ≤ 9
Try Examples
Custom:
Phase 1 — Find Middle
State Variables
Phase
left.val
right.val
Match?
Step Logic
Press ▶ Play or Next Step to begin the animation.
🎉
Ready
0 / 0
Select an example above and press Play.
Algorithm
1
Find Middle: slow advances 1 step, fast advances 2. When fast hits end, slow is at the midpoint.
2
Reverse 2nd half: Standard in-place reversal from slow. prev ends up as the new right-half head.
3
Compare halves: left from head, right from prev. Any mismatch → return false.
4
All pairs matched → return true (it is a palindrome).
Time
O(n)
Space
O(1)
Why This Works

A palindrome reads the same forwards and backwards. By reversing the second half in-place we avoid using a stack (O(n) space). The slow/fast pointer trick finds the midpoint in a single O(n) pass. The final comparison is also O(n). Total: O(n) time, O(1) space.