boolean hasCycle(Node head) {
int count1=1;
int count2=2;
if(head==null){
return false;
}
if(head.next==null){
return false;
}
if(head.next.next==null){
return false;
}
Node temp1=head.next;
Node temp2=head.next.next;
while(temp1==temp2){
if(temp1.next==null || temp2.next==null || temp2.next.next==null ||temp1==null||temp2==null){
return false;
}
temp1=temp1.next;
temp2=temp2.next.next;
if(temp1==temp2){
return true;
}
}
if(temp1==null)
return false;
return true;
}