Skip to content
Onsite

Palindrome Linked List

EasyP2Coding

Given the head of a singly linked list, return true if its values read the same from front to back and from back to front, otherwise false. A list node has val and next. The ListNode class is already defined for you.

Aim for O(n) time and O(1) extra space.

Example 1

Input
head = [1,2,2,1]
Output
true

Example 2

Input
head = [1,2,3]
Output
false

Example 3

Input
head = [7]
Output
true

Constraints

  • 0 <= number of nodes <= 10^5
  • 0 <= Node.val <= 9

Hints

Run checks the 3 visible tests, Submit all 12.