You are viewing a single comment's thread. Return to all comments →
What is the problem with this code?
boolean hasCycle(Node head) { Node slow,fast; if(head==null ){ return false; } slow=head; fast=head.next; while(fast!=null||fast.next!=null){ if(slow==fast) return true; slow=slow.next; fast=fast.next.next; } 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 →
What is the problem with this code?