Check if a Linked List is a Palindrome
You are given the head of an acyclic singly linked list. Examples serialize its node values in order from head → tail. Return true if the list reads the same…
You are given the head of an acyclic singly linked list. Examples serialize its node values in order from **head → tail**. Return `true` if the list reads the same forwards and backwards (a palindrome), and `false` otherwise. An empty list and a single-node list are palindromes by definition. The function may change `next` pointers; preserving the original list is not part of this Boolean-result contract. The values use 0-based positions: `[1, 2, 3, 2, 1]` means 1 → 2 → 3 → 2 → 1 → null, which is a palindrome, so the answer is `true`.
- `0 <= nodes.length <= 10^5` - `-10^9 <= nodes[i] <= 10^9` - The list is a proper singly linked list with no cycles.
Example 1: input nodes = [1,2,3,2,1]; output true. The values 1,2,3,2,1 read identically forwards and backwards.
Example 2: input nodes = [1,2,2,1]; output true. Even-length palindrome — 1,2,2,1 mirrors around the centre.
Example 3: input nodes = [1,2,3,4]; output false. Reading backwards gives 4,3,2,1, which differs from 1,2,3,4.
Category: Linked List. Topic: linked-list. Difficulty: Medium. Patterns: linked-list-traversal, fast-slow-pointers, in-place-reversal.