Palindrome Linked List
Given the head of a singly linked list, return true if the sequence of node values reads the same forwards and backwards (a palindrome), and false otherwise.
Open official problem prompt ↗Decide whether the values along a singly linked list form a palindrome, ideally without allocating extra memory proportional to the list length.
Folding a strip of paper in half: if every letter on the top half lines up with the letter beneath it, the word reads the same both ways.
- Input
- head = [1,2,2,1]
- Output
- true
- Why
- Reading the values forward gives 1,2,2,1 and backward gives 1,2,2,1, which are identical.
The number of nodes is in the range [1, 10^5]0 <= Node.val <= 9Follow up: solve in O(n) time and O(1) space