Palindrome Linked List - Problem
Given the head of a singly linked list, return true if it is a palindrome or false otherwise.
A palindrome is a sequence that reads the same forward and backward.
Example: The linked list 1 → 2 → 2 → 1 is a palindrome because it reads the same forwards and backwards.
Input & Output
Example 1 — Basic Palindrome
$
Input:
head = [1,2,2,1]
›
Output:
true
💡 Note:
The linked list reads the same forwards (1→2→2→1) and backwards (1→2→2→1), so it's a palindrome.
Example 2 — Not a Palindrome
$
Input:
head = [1,2]
›
Output:
false
💡 Note:
The linked list reads 1→2 forwards but 2→1 backwards, which are different, so it's not a palindrome.
Example 3 — Single Node
$
Input:
head = [1]
›
Output:
true
💡 Note:
A single node is always a palindrome since it reads the same forwards and backwards.
Constraints
- The number of nodes in the list is in the range [1, 105]
- 0 ≤ Node.val ≤ 9
Visualization
Tap to expand
Understanding the Visualization
1
Input
Linked list: 1→2→2→1
2
Check
Compare forwards vs backwards reading
3
Output
Return true if palindrome
Key Takeaway
🎯 Key Insight: Find the middle, reverse second half, then compare both halves for optimal O(1) space solution
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code