Given the head of a linked list, determine if the list contains a cycle. A cycle exists if some node in the list can be reached again by continuously following the next pointer.
The test case provides an extra parameter pos — the index of the node that the tail's next pointer connects to (-1 means no cycle). pos is not passed as a function argument — it is only used to construct the input list.
Use Floyd's Tortoise and Hare: advance slow by one and fast by two; the two pointers meet inside the cycle if and only if a cycle exists.
Example: head = [3,2,0,-4], pos = 1 → true (tail connects back to index 1). head = [1,2], pos = -1 → false.
true