Palindrome Linked List
1 approach, code in every language
Problem description
Given the head of a singly linked list, determine whether the sequence of values forms a palindrome, meaning it is identical when read from front to back and from back to front.
Return true when the values are symmetric and false otherwise. An empty list and a single-node list are trivially palindromes.
Example 1
Input: head = [1,2,2,1]
Output: true
Reading the values forward gives 1,2,2,1 and reading them backward gives the same sequence.
Example 2
Input: head = [1,2,3]
Output: false
Forward the values are 1,2,3 but backward they are 3,2,1, so the list is not symmetric.
Constraints
The number of nodes in the list is in the range [1, 10^5].0 <= Node.val <= 9
Create a free account to see the solution
You get the step-by-step animation, the intuition and clean code in every language. Free, no credit card.
After the pattern
Now solve one you haven't seen.
Stamp Chain Echo is our own problem on the technique behind Palindrome Linked List: a new statement, so there's no answer to remember. Write it in your browser and run it against graded tests.
1,194 problems · 15,062 graded tests · free