Description
Given the head of a singly linked list, return true if it is a palindrome or false otherwise. A linked list palindrome reads the same forwards and backwards when considering the values of the nodes.
Examples
Input:
head = [1,2,2,1]Output:
trueExplanation:
The linked list reads the same forward and backward.
Input:
head = [1,2]Output:
falseExplanation:
[1,2] is not a palindrome.
Input:
head = [1]Output:
trueExplanation:
A single-element list is always a palindrome.
Constraints
- •
The number of nodes is in the range [1, 10⁵]. - •
0 ≤ Node.val ≤ 9