Solution 1: accepted 1ms
- A: the distance from the beginning to the start of the cycle
- B: the distance slow pointer moved the start of the cycle
- L: the length of the cycle
So the slow pointer has moved A+B, therefore the fast pointer 2A+2B. Since the fast pointer have moved L more steps, we have A+B+L=2A+2B –> L=A+B. Since L=A+B, the slow pointer has moved B, the rest of the cycle(back to the starting point) is A, the same as the distance from head to the start of the cycle.
|
|
Without dummy