Linked List Cycle
Solution ApproachWas this helpful?
Easy•linked-list•Expected: O(n) time, O(1) space
two-pointerslinked-list
Problem
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.
Reference solution unlocks after your first submission
Loading...
