Timeline
timeline
2026-03-13
init
linked list, two pointers
Problem:
First meeting, fast pointer has moved2 * ksteps, slow pointer has moved k steps, let length outside cycle be m, cycle length L
Fast pointer has gone n more laps(nL) i.e.k = nL, i.e. slow pointer has movednLsteps
Slow pointer then moves m more steps, totalm+nLsteps to reachm+nL= cycle entrance
Note that the following loop should not use do while, because a linked list may be a circular linked list, and the length outside the cycle is 0
1 | /** |
