Intermediate Level
Implement the detectCycleLinkedListValues method that checks whether the linked list has a cycle at the given position.
The linked list is provided as an integer array nodes, its length size, and an integer pos.
The value pos represents the index where the tail connects back into the linked list. If pos is -1, the linked list has no cycle.
Your task is to return true if the linked list contains a cycle, otherwise return false.
In a real linked list, cycle detection is commonly solved using the slow and fast pointer method. If the fast pointer meets the slow pointer, a cycle exists.
In this problem, the cycle position is provided directly as pos. If pos is a valid index inside the list, the tail connects to that node and the list has a cycle. If pos is -1, there is no cycle.
Pseudocode:
function detectCycleLinkedListValues(nodes, size, pos):
if pos >= 0 and pos < size:
return true
return false