Given a linked list represented as an array of values and a `pos` value indicating where the tail connects to (0-indexed), determine if the linked list has a cycle.
The `pos` parameter indicates the index of the node that the tail's next pointer is connected to. If `pos` is `-1`, there is no cycle.
Return `true` if there is a cycle, `false` otherwise.
Note: In a real linked list, you would use Floyd's cycle detection. Here, since we have the position, you can determine the answer directly from the input.
Example 1
Input:head = [3, 2, 0, -4], pos = 1
Output:true
Explanation:The tail connects to node index 1, creating a cycle.
Example 2
Input:head = [1, 2], pos = 0
Output:true
Explanation:The tail connects to node index 0, creating a cycle.
Example 3
Input:head = [1], pos = -1
Output:false
Explanation:There is no cycle.
Constraints
- The number of nodes is in the range [0, 10^4].
- -10^5 <= Node.val <= 10^5
- pos is -1 or a valid index in the linked list.