Cycle exists
Input
[3,2,0,-4], 1
Output
True
Tail connects to node index 1, creating a cycle.
Full lesson preview
Detect whether a singly linked list has a cycle using Floyd's Tortoise and Hare algorithm.
Problem statement
Task
Examples
Input
[3,2,0,-4], 1
Output
True
Tail connects to node index 1, creating a cycle.
Input format
Output format
Constraints
Samples
Input
[3,2,0,-4], 1
Output
True
There is a cycle because tail connects to index 1.