Detect whether a linked list loops back on itself. Slow ๐ข takes one step,
fast ๐ takes two. If there's a cycle they're guaranteed to meet inside it;
if not, fast runs off the end. Set the values and where the tail links back.
Execution
idle
Press Run to begin.
0 / 0
Speed
Java ยท running line
slow ๐ขfast ๐meeting pointnull / end
O(n) time ยท O(1) space ยท the gap between the pointers shrinks by one node each loop,
so inside a cycle a collision is inevitable.