You are viewing a single comment's thread. Return to all comments →
boolean hasCycle(Node head) { if(head == null ){ return false; } Node tortoise=null; Node hare = null; hare = tortoise = head; while(hare!=null && hare.next!=null){ tortoise = tortoise.next; hare = hare.next.next; if(tortoise == hare){ 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 →