Search topics...

Linked List Cycle

easy
linked-listTime: O(n)Space: O(1)Frequency: 5

Given the head of a linked list, determine if the linked list has a cycle in it.

Example 1:

Input: head = [3, 2, 0, -4], pos = 1
Output: true
Explanation: There is a cycle where the tail connects to the 1st node (0-indexed).

Example 2:

Input: head = [1], pos = -1
Output: false
Explanation: No cycle in the linked list.
two-pointerslinked-list