DSA AnimatorDSA animations
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.

How to solve Palindrome Linked List

LeetCode 234 · Easy · Linked List · Pattern: Fast & Slow + Reverse

Why the obvious approach is slow

Copying the values into an array and checking with two pointers uses O(n) space. We cannot walk a singly linked list backwards.

The key idea

Find the middle with fast and slow pointers. Reverse the second half. Then compare the first half with the reversed second half, node by node.

Remember

Middle, reverse, compare. Three small linked list tools combine into one solution.

Run the animation above on your own input, or watch the 1:03 video explanation of Palindrome Linked List with a dry run and Java code.

More Linked List problems