Skip to content

Palindrome Linked List

EasyLinked List
Decode it first. Clues, constraints, pattern and plan before any code.

Given the head of a singly linked list, return True if its values read the same forwards and backwards, and False otherwise. Can you do it in O(n) time and O(1) extra space?

1 -> 2 -> 2 -> 1        →  True
1 -> 2 -> 3 -> 2 -> 1   →  True
1 -> 2                  →  False

Constraints

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