Cycle Detection

  • + 0 comments

    This question does have bugs in some languages, such as JavaScript. I ran the following which is exactly equivalent to the working Python 3 solution already posted. That solution passes in Python, but it does not pass in JavaScrpt.

    function hasCycle(head) { let node = head; const visited = {}; while (node) { if (visited[node]) return true; visited[node] = true; node = node.next; } return false; }