Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null.
Input encoding: the list values, then a line with pos — the 0-indexed node the tail's next connects to (-1 for no cycle). The judge reports the index of your returned node (-1 for null).
- The number of nodes is in the range [0, 10^4] - -10^5 <= Node.val <= 10^5
Detect the cycle with slow/fast. Once they meet, reset one pointer to head and advance both one step at a time; they meet again exactly at the cycle's entry node.
O(n) time, O(1) space.