4 ms·
The naive way to do it is just create a hashset that stores pointer to next, walk the linked list, and if you get a collision you have a cycle. The problem is t
by bradleyjg 12y ago
The naive way to do it is just create a hashset that stores pointer to next, walk the linked list, and if you get a collision you have a cycle. The problem is that it requires O(n) memory, where the tortoise and hare method only needs O(1).