Back to exercises

Detect Cycle in Linked List

Move one pointer one step and another pointer two steps at a time. If they ever meet, there is a cycle; if the fast pointer reaches the end, the list is acyclic.

Coding Exercises Easy O(n)

Detect Cycle in Linked List

Move one pointer one step and another pointer two steps at a time. If they ever meet, there is a cycle; if the fast pointer reaches the end, the list is acyclic.

Return whether a linked list contains a cycle.