Palindrome Linked List
Given the head of a singly linked list, return true if it is a palindrome or false otherwise.
Follow up: Could you do it in O(n) time and O(1) space?
Example 1
[1] -> [2] -> [2] -> [1] -> null
Input
head = [1,2,2,1]Output
trueThe list reads the same forward and backward, so it is a palindrome.
Example 2
[1] -> [2] -> null
Input
head = [1,2]Output
falseThe list does not read the same forward and backward, so it is not a palindrome.
Constraints
- The number of nodes in the list is in the range
[1, 10^5]. 0 <= Node.val <= 9