Linked List Cycle II

medium

Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null.

Input encoding: the list values, then a line with pos — the 0-indexed node the tail's next connects to (-1 for no cycle). The judge reports the index of your returned node (-1 for null).

Constraints

- The number of nodes is in the range [0, 10^4] - -10^5 <= Node.val <= 10^5

Solve this problem →