#142

Linked List Cycle II

Medium Floyd's cycle entrance

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

?The problem

Return the node where a linked list's cycle begins, or null if there is no cycle.

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

◎Understanding

Really asking: where does the cycle start?

Why this works: after slow and fast meet, the distance from head to the entrance equals the distance from the meeting point to the entrance. Walk both at speed 1.

Example: 3 → 2 → 0 → -4 → (2)

meet at -4one pointer from 3, one from -4: next steps land on 2 together → entrance 2

✦Hints open one at a time

↗Approach

</>Solution (Java)

!Common mistake

Returning the meeting point itself — it's somewhere inside the cycle, not necessarily the start.

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