Linked List Cycle II

Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null. Do not modify the list. Example: Input: head = [3,2,0,-4], pos = 1 Output: Reference to node with value 2 Explanation: Cycle starts at node index 1 (value 2). Pattern focus: List Cycle Entry (find cycle start via two pointers).

Input Format

head = ListNode

Output Format

return ListNode

Constraints

  • The number of nodes is in the range [0, 10^4].
  • -10^5 <= Node.val <= 10^5
  • `pos` is the index of the cycle start or -1.

Examples

Example 1:

Input:

head = [3,2,0]

Output:

-1

Example 2:

Input:

head = [1,2]

Output:

-1
Loading...
Linked List Cycle II - Linked List DSA Problem