Linked List Cycle
Given head, the head of a linked list, determine if the linked list has a cycle in it. A cycle exists if there is some node that can be reached again by continuously following the next pointer.

30:00

Linked List Cycle
easy
Topics
Companies

Given head, the head of a linked list, determine if the linked list has a cycle in it. A cycle exists if there is some node that can be reached again by continuously following the next pointer.

Example 1:
Input: {"head":[3,2,0,-4],"pos":1}
Output: true
Constraints:
  • The number of nodes is in the range [0,104][0, 10^4].

  • 105Node.val105-10^5 \leq \text{Node.val} \leq 10^5

  • pos\text{pos} is 1-1 or a valid index in the linked list.

Input
arr ={"head":[3,2,0,-4],"pos":1}

Init: slow = head, fast = head

slowfast

3

2

0

-4

To 2
Variables
No variables to display
DepthFunction Call
Stack empty
0/12