The problem. Given head, return the node where the cycle begins. If there is no cycle, return null. You must not modify the list.
Input: head = [3, 2, 0, -4], tail connects to index 1
Output: the node 2 (index 1)
Input: head = [1], no cycle
Output: nullThis builds directly on Linked List Cycle: first decide whether there's a loop, then find its entrance.
Members only · free account
The rest of this lesson, with 5 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson