Detect Cycle
If fast ever lands on slow, the list loops. On a straight list fast just runs out.
Fast and Slow Pointers: A list that loops
Step 1: slow to 2, fast to 3.
Cost
- Best
- O(n)
- Average
- O(n)
- Worst
- O(n)
- Space
- O(1)
Before this
Related
Leads to
Topics that need this one first.
Taught by the same lesson
Fast and Slow Pointers covers these too, in the same run.