You are viewing a single comment's thread. Return to all comments →
static boolean hasCycle(SinglyLinkedListNode head) { Map<Integer, Integer> visited = new HashMap<>(); boolean visitedMore = false; while (head != null) { int clazz = head.hashCode(); int currentNodeData = visited.getOrDefault(clazz, 0); visited.put(clazz, currentNodeData + 1); if (currentNodeData > 1) { visitedMore = true; break; } head = head.next; } return visitedMore; }
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 →