Find Length of Loop

medium

Given the head of a linked list that may contain a loop, return the length of the loop (the number of nodes in the cycle). If there is no loop, return 0.

Input encoding: the list values, then a line with pos — the 0-indexed node the tail's next connects to (-1 for no loop). pos builds the list; your function receives just head.

Constraints

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

Solve this problem →