Palindrome list
Standard · Write code · about 15 min
Given the head of a singly linked list, return true if its values read the same forward and backward. Aim for O(n) time and O(1) extra space.
Example 1
Input:
[[1,2,2,1]]
Output:
true
Example 2
Input:
[[1,2,3]]
Output:
false
1 and 3 differ.
Constraints
- 0 ≤ number of nodes ≤ 5,000
- 0 ≤ node value ≤ 9
Learn the idea first: Linked list techniques: reverse, middle, merge, detect a cycle, a visual lesson.
More Linked list techniques: reverse, middle, merge, detect a cycle problems
- Reverse a list Warm-up
- Middle node Warm-up
- Merge two sorted lists Standard
- Trace a list reversal Standard
- Find the cycle start Challenge