Back to problems Sign in to unlock
Leetcode
Medium
Linked Lists
Stacks
Two Pointers
Amazon
Microsoft
Palindrome Linked List
Determine whether a singly linked list reads the same forward and backward.
Acceptance 100%
Problem Statement
Given the head of a singly linked list, determine whether the sequence of node values forms a palindrome.
A list is a palindrome if reading the values from left to right gives the same result as reading them from right to left.
You should return true if the list is palindromic and false otherwise.
Input Format
- A singly linked list is provided via its head node.
- Each node contains an integer value.
- The list may be empty.
Output Format
- Return
trueif the linked list is a palindrome. - Otherwise, return
false.
Constraints
- The linked list can contain any integer values.
- Aim for time.
- Use extra space if possible.
Examples
Sample cases returned by the problem API.
Example 1
Input
head = [1,2,2,1]
Output
true
Explanation
The values read the same from both directions.
Example 2
Input
head = [1,2]
Output
false
Explanation
The forward order is [1,2], while the reverse order is [2,1].
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.