You are viewing a single comment's thread. Return to all comments →
Java 8
static boolean hasCycle(SinglyLinkedListNode head) { Set<SinglyLinkedListNode> nodeSet = new HashSet<>(); SinglyLinkedListNode node = head; while (node != null) { if (nodeSet.contains(node)) { return true; } nodeSet.add(node); node = node.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 →
Java 8