You are viewing a single comment's thread. Return to all comments →
Any idea why this is throwing a timeout request. It seems to pass the given test case on paper.
boolean hasCycle(Node head) { if(head == null){ return false; } else{ Node current = head; while(current.next != null){ Node incNode = current.next; if(incNode == current){ return true; } else{ while(incNode.next != null){ if(incNode.next == current){ return true; } incNode = incNode.next; current = current.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 →
Any idea why this is throwing a timeout request. It seems to pass the given test case on paper.