/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
bool hasCycle(struct ListNode *head) {
struct ListNode *fast_p=head,*slow_p=head;
while(fast_p!=NULL&&fast_p->next!=NULL){
slow_p=slow_p->next;
fast_p=fast_p->next->next;
if(slow_p==fast_p) {
return true;
}
}
return false;
}