You are viewing a single comment's thread. Return to all comments →
For anyone wants to compare this with a HashSet solution:
boolean hasCycle(Node head) { Set<Node> seen = new HashSet<>(); while (head != null) { seen.add(head); head = head.next; if (seen.contains(head)) return true; } return false; }
Seems like cookies are disabled on this browser, please enable them to open this website
Linked Lists: Detect a Cycle
You are viewing a single comment's thread. Return to all comments →
For anyone wants to compare this with a HashSet solution: