Both are O(n) time.
The HashSet is simpler: the first node you see twice is the loop start. But it stores nodes, so it needs O(n) memory.
Fast and slow pointers need only O(1) memory. In an interview, give the HashSet idea first, then improve it.
#ll012 · LL-012-A3
