Given the head of a linked list, return True if the list has a cycle, False otherwise.
A linked list has a cycle if some node in the list can be reached again by continuously following the next pointer.
Example 1:
Input: head = [3,2,0,-4], pos = 1 Output: True Explanation: There is a cycle; the tail connects to the node at index 1.
Example 2:
Input: head = [1,2], pos = 0 Output: True Explanation: There is a cycle; the tail connects to the node at index 0.
Example 3:
Input: head = [1], pos = -1 Output: False Explanation: There is no cycle; pos = -1 means the tail has no next pointer.
[0, 10^4]-10^5 <= Node.val <= 10^5pos is -1 or a valid index in the linked list (-1 means no cycle)head = [3,2,0,-4], pos = 1