Floyd's cycle detection finds a loop in a sequence (like a linked list) using two pointers moving at different speeds. If a cycle exists, the fast pointer eventually laps and meets the slow one. It uses O(1) extra space.
The idea
Move a slow pointer one step and a fast pointer two steps. In a cycle, the gap shrinks by one each step, so they must collide; without a cycle, fast reaches the end.
Example
():
slow = fast = head
fast fast.:
slow = slow.
fast = fast..
slow fast:
