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
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code