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
head: integer[] representing linked-list node valuesExamples
[1,2,2,1] returns true.[1,2] returns false.Constraints
1 <= head.length <= 100,000-100,000 <= head[i] <= 100,000Follow-up With real nodes, can you solve it in linear time and constant space while restoring the list afterward?