Search for a command to run...
Reset slow pointer to head and advance both slow and fast at equal speed to locate the cycle entrance
Phase 1: Cycle Detection
Initialize slow and fast pointers at the head of the list.
Floyd's Start Finding
1class Solution {2 findStartingPoint(head) {3 let slow = head;4 let fast = head;5 6 // Phase 1: Detect loop7 while (fast !== null && fast.next !== null) {8 slow = slow.next;9 fast = fast.next.next;10 11 if (slow === fast) {12 // Reset slow to head//slow: 1fast: 113 slow = head;14 15 // Phase 2: Find entrance16 while (slow !== fast) {17 slow = slow.next;18 fast = fast.next;19 }20 return slow;21 }22 }23 return null;24 }25}