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.
- The number of nodes is in the range [0, 10^4] - -10^5 <= Node.val <= 10^5
Use Floyd's cycle detection to find a meeting point inside the loop. From there, walk around the loop once, counting nodes until you return to the meeting point.
O(n) time, O(1) space.