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
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.