#11

Linked List Cycle

Easy
All Problems

11. Linked List Cycle#141

Easy🔗 Linked ListFast & Slow Pointers

Determine if a linked list has a cycle in it.

Examples

Example 1:
Input: [[3,2,0,-4],1]
Output: true
Example 2:
Input: [[1,2],0]
Output: true
Example 3:
Input: [[1],-1]
Output: false

Why learn this

Floyd's cycle detection — a classic CS algorithm with a beautifully simple implementation.

Linked ListsTwo PointersFloyd's Algorithm
Python 3Loading Python engine...
Click "Run Code" to test your solution