easy
linked-list
two-pointers
Determine whether the values in a singly linked list read the same forward and backward. In the current judge contract, head is serialized as an integer array in traversal order.
Input / output
- Input:
head: integer[]representing linked-list node values - Output: boolean
Examples
[1,2,2,1]returnstrue.[1,2]returnsfalse.
Constraints
1 <= head.length <= 100,000-100,000 <= head[i] <= 100,000
Follow-up With real nodes, can you solve it in linear time and constant space while restoring the list afterward?
Examples
Example 1
Input: head = [1,2,2,1]
Output: true
Example 2
Input: head = [1,2]
Output: false
Example 3
Input: head = [1]
Output: true
🔒 5 hidden
Running will execute all 8 cases, including 5 hidden ones.