Given the head of a linked list, determine if it is a palindrome (reads the same forward and backward). Use O(n) time and O(1) extra space. Example: Input: head = [1,2,2,1] Output: true Explanation: The list forwards/backwards are both [1,2,2,1]. Pattern focus: Fast and Slow Pointers (find middle, reverse second half).
head = ListNode
return boolean
Example 1:
Input:
head = [1,2,2,1]
Output:
true
Explanation:
Sequence is same forwards/backwards.
Example 2:
Input:
head = [1,2]
Output:
false
Explanation:
Forwards [1,2] ≠ backwards [2,1].