Loading problem…
Given the head of a singly linked list, return true if it is a palindrome or false otherwise.
Example 1
Input: head = [1,2,2,1]
Output: true
Explanation: The values read 1, 2, 2, 1 forwards and 1, 2, 2, 1 backwards, so the list is a palindrome.
Example 2
Input: head = [1,2]
Output: false
Explanation: Forwards the list is 1, 2 but backwards it is 2, 1, so it is not a palindrome.
Example 3
Input: head = [1]
Output: true
Explanation: A single node reads the same in both directions.
Find the middle with slow/fast pointers, reverse the second half in place, then compare it against the first half node by node — O(1) extra space.
Run checks all cases above. Submit evaluates all test cases.