Palindrome Linked List

Linked Lists, problem 4 of 10

Palindrome Linked List

Easy

LC #234

fast & slow pointersin-place reversal

Not attempted yet

Given the head of a singly linked list, return True if its values read the same forwards and backwards, otherwise False.

Example 1

Input: head = [1,2,2,1]
Output: True

Example 2

Input: head = [1,2]
Output: False

Example 3

Input: head = [1,2,1]
Output: True

Constraints

  • 0 ≤ number of nodes ≤ 10⁵
  • -10⁵ ≤ Node.val ≤ 10⁵

Can you do it in O(n) time and O(1) extra space?

Python

Loading draft…

Test results

11 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 8 hidden

Run examples, then submit all tests.