You are viewing a single comment's thread. Return to all comments →
Using Floyd Cycle alogrithm O(n)
oolean hasCycle(Node head) {
Node slowPtr=head; Node fastPtr=head; while(fastPtr!=null && fastPtr.next!=null) { fastPtr=fastPtr.next.next; slowPtr=slowPtr.next; if(slowPtr==fastPtr) return true; } return false;
}
Cycle Detection
You are viewing a single comment's thread. Return to all comments →
Using Floyd Cycle alogrithm O(n)
oolean hasCycle(Node head) {
}