You are viewing a single comment's thread. Return to all comments →
Did it using HashSet in Java, no problem.
boolean hasCycle(Node head) { if (head == null) return false; Node hare = head; HashSet<Node> nodesVisited = new HashSet<Node>(); while (hare != null) { if (nodesVisited.contains(hare)) return true; nodesVisited.add(hare); hare = hare.next; } return false; }
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 →
Did it using HashSet in Java, no problem.