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:true
Explanation:

The linked list reads the same forward and backward.

Input:head = [1,2]
Output:false
Explanation:

[1,2] is not a palindrome.

Input:head = [1]
Output:true
Explanation:

A single-element list is always a palindrome.

Constraints

  • The number of nodes is in the range [1, 10⁵].
  • 0 ≤ Node.val ≤ 9

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!