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 <= 9See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.
FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI