Return the number of nodes in the cycle, or 0 if the list has no cycle.
A list can have a cycle: the last node's next points back at an earlier node. The tests give such a list as {"values": [...], "cycle": k}, where the last node points back at node k (counting from 0), and k = -1 means no cycle.
Example 1
Input:
cycle_length(head) # head = 3 -> 2 -> 0 -> -4, and -4 points back at 2
Output:
3
Example 2
Input:
cycle_length(head) # head = 1 -> 2, no cycle
Output:
0
0 <= number of nodes <= 100000k is -1 or a valid index.No results yet
Run your code to check it against the examples, or submit to run every test.