/**
*环形链表判断/ 快跑法 追上则是环
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
bool hasCycle(ListNode *head) {
ListNode *head1=head;
int flag=0;
if(head==NULL){
return false;
}
while(true){
if(head->next==NULL||head->next->next==NULL){
break;
}
head=head->next;
head=head->next;
head1=head1->next;
if(head==head1){
flag=1;
//cout<<111111;
break;
}
}
if(flag==0){
return false;
}else{
return true;
}
}
};