List that reads the same backwards
Write is_palindrome(head): return True if the values of a singly linked list read the same front to back as back to front, like 1 → 2 → 2 → 1 or 3 → 7 → 3, and False otherwise. An empty list (head is None) and a single node both count as palindromes. Each ListNode has val and next.
Use O(n) time and O(1) extra memory: no list, stack or string of the values. You may re-link nodes while you check, but the list must be back as you found it when you return.
The tests call the provided run_is_palindrome(values), which builds the list from values, calls your function and checks that the list was restored.
Besides the tests, one large input (a 6,000-node list) with a ~95 ms limit (scaled to your device's speed): brute force won't pass.
Examples
run_is_palindrome([1,2,2,1])→truerun_is_palindrome([3,7,3])→truerun_is_palindrome([1,2,3,1])→false