You are given the head of a singly linked list. Your task is to determine whether the linked list forms a palindrome. Return true if it reads the same forward and backward; otherwise, return false.
Example 1
Input: head = [1,2,2,1]
Output: true
Explanation: The linked list reads the same from left to right and right to left.
Example 2
Input: head = [1,2,3,2,1]
Output: true
Explanation: The linked list is symmetric, so it is a palindrome.
Example 3
Input: head = [1,2,3]
Output: false
Explanation: The linked list does not read the same in both directions.
Sign in to write, run, and submit your solution against the full test suite.