We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Cycle Detection
You are viewing a single comment's thread. Return to all 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; }