← Visualizers
Fast & Slow Pointers LeetCode 141

Linked List Cycle / visualized

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 point null / 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.