Skip to main content
CodeOath
← All problems

Problem

Palindrome Linked List

Easy
  • linked-list
  • two-pointers

Return true if the values of the singly linked list head read the same from the front as from the back, and false if they do not. A list with a single node counts as a palindrome.

Lists in this problem are written as a plain array of values, in order.

Example 1
Input
head = [3, 7, 9, 7, 3]
Output
true
Explanation

read backwards, the values are still 3, 7, 9, 7, 3.

Example 2
Input
head = [4, 5, 6, 4]
Output
false
Explanation

backwards it is 4, 6, 5, 4, which differs from 4, 5, 6, 4 in the middle.

Constraints:

  • the list has at least one node

Follow-up: copying the values into an array is the easy route. Can you check the list using only a fixed amount of extra memory?

Tab indents. Press Esc, then Tab to leave the editor.

Run your code to see every test here. Nothing is submitted or recorded.