Given the
head of a linked list, return the node where the
cycle begins. If there is no cycle, return
null. A cycle exists in a linked list if some node can be reached again by continuously following the
next pointer. Do not modify the linked list.
Example 1:
Input: head = [3,2,0,-4], pos = 1
Output: Node with value 2
Explanation: The tail node connects back to the node at index
1. The cycle begins at the node having value:
2
Example 2:
Input: head = [1,2], pos = 0
Output: Node with value 1
Explanation: The tail node connects back to the first node itself, so the cycle starts at node:
1
Example 3:
Input: head = [1], pos = -1
Output: null
Explanation: The linked list does not contain any cycle.