Skip to content
StackDecode
Linked listsAnimated

Palindrome Linked List

Reverse the second half and compare it with the first.

Time

O(n)

Extra space

O(1)

Use it for

Checking symmetry in place.

How it works

  1. Find the middle with slow/fast pointers.
  2. Reverse the second half of the list in place.
  3. Walk from the head and from the start of the reversed half together, comparing values.
  4. If every pair matches it is a palindrome. O(n) time, O(1) memory.

Watch it run

Loading animation…