Linked List Cycle Detection
Easy
Linked Lists
Linked List
Two Pointers
Given a sequence of values representing linked list nodes and a cycle position (-1 for no cycle), return true/false.
Constraints
0 ≤ nodes ≤ 10^4
Examples
Example 1:
Input: 3 2 0 -4
1
Output: true
Explanation: Cycle at position 1
Example 2:
Input: 1 2
0
Output: true
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console