Re:Linked List Problems (2002) [pdf]
by xamuel on Saturday November 25, 2017 @08:26AM
(#15775883)
You didn't say the answer has to use O(1) space, so I'd just throw the nodes in a WeakSet, and when I reach a node that's already in the WeakSet, that's the start of the loop. Or better yet, use a WeakMap to associate nodes with their position, so that once I find the start of the loop I can immediately subtract to get the loop length, no second pass needed.
[ Parent
| on HN ]
There are no comments on this comment yet.