Given the head of a linked list, determine if the linked list has a cycle in it. pos denotes the index the tail connects back to (-1 means no cycle). Return true if there is a cycle, or false otherwise.
Input: values = [3,2,0,-4], pos = 1
Output: true
Topics: linked-list, two-pointers
Asked by: Amazon, Google, Meta, Microsoft, Bloomberg
Time complexity: O(n). Space complexity: O(1).