142. Linked List Cycle II
Assume fast
goes 2k
steps and slow
goes k
steps, then they meet. Assume slow goes steps, fast goes steps, .
So in math,
Obviously,
Assume (fast only need to step one round more than 2*slow)
When slow = fast
, let slow
continues moving and start
move at the same time at the same step until they meet. The steps start
walks is the circle meeting.
Initializestart = head
and slow = head
. After they move then compare them.
Last updated