Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null.
There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to (0-indexed). It is -1 if there is no cycle. Note that pos is not passed as a parameter.
Do not modify the linked list.
This extends the basic cycle detection to find the exact starting point of the cycle. After detecting a cycle with Floyd's algorithm, there's a beautiful mathematical property: if you reset one pointer to the head and move both pointers one step at a time, they will meet at the cycle's starting node.
head = [3,2,0,-4], pos = 1Node at index 1 (value = 2)head = [1,2], pos = 0Node at index 0 (value = 1)head = [1], pos = -1nullThe number of nodes in the list is in the range [0, 10^4]-10^5 <= Node.val <= 10^5pos is -1 or a valid index in the linked-listClick "Run" to execute your code against test cases
Socratic guidance - I'll ask questions, not give answers