head = [3,2,0,-4], pos = 1node 1 (val=2)Return the original node where the next links begin to repeat. If the chain ends at None, return None. Do not change any node values or links.
head = [3,2,0,-4], pos = 1node 1 (val=2)Values describe the nodes. pos is the zero-based index that the tail connects to; -1 means no cycle. The editor builds that connection and supplies ListNode with val and next. Your function receives only head and must return a node, not its value or index.
LeetCode 142head = [3,2,0,-4], pos = 1 result = node 1 (val=2)
Each distinct node is added once before a repeat or None. With average O(1) hash-set operations, time complexity is O(N). N counts distinct nodes.
The set may hold all N node references, so extra space is O(N).
head = [3,2,0,-4], pos = 1 result = node 1 (val=2)
Both approaches take linear time. Floyd's algorithm removes the growing visited set and uses constant extra space. Neither approach changes the list.
Detection and entry search together take O(N) time, where N is the number of distinct nodes, including the cycle.
Only slow, fast, and entry references are stored: O(1) extra space.