Given the head of a singly linked list, return true if it is a palindrome, or false otherwise.
head = [1,2,2,1]truehead = [1,2]falseslow. prev ends up as the new right-half head.left from head, right from prev. Any mismatch → return false.A palindrome reads the same forwards and backwards. By reversing the second half in-place we avoid using a stack (O(n) space). The slow/fast pointer trick finds the midpoint in a single O(n) pass. The final comparison is also O(n). Total: O(n) time, O(1) space.