Problem
Given the head of a singly linked list, return True if its values read the same forwards and backwards, and False otherwise. Can you do it in O(n) time and O(1) extra space?
Example 1
- Input
- 1
- Output
- 2 -> 2 -> 1 → True
Example 2
- Input
- 1
- Output
- 2 -> 3 -> 2 -> 1 → True
Example 3
- Input
- 1
- Output
- 2 → False
Constraints
1 <= number of nodes <= 10^50 <= Node.val <= 9