#234

Palindrome Linked List

Easy Middle + reverse second half

  1. Read
  2. Understand
  3. Hints
  4. Approach
  5. Solution
  6. Solved

?The problem

Decide whether a singly linked list reads the same forwards and backwards, ideally in O(1) extra space.

This is a short summary in our own words. Read the full statement and examples on LeetCode: open problem ↗

◎Understanding

Really asking: does the list read the same backwards?

Why this works: find the middle, reverse the second half, compare the two halves node by node.

Example: 1 → 2 → 2 → 1

second half reversed: 1 → 2compare 1=1, 2=2 → true

✦Hints open one at a time

↗Approach

</>Solution (Java)

!Common mistake

Copying values into an ArrayList — correct, but O(n) space.

Solve on LeetCode ↗
Complexity
  • Time: O(n).
  • Space: O(1).
Topic: Linked List
🎬 Episodes 40–45: video coming soon