class Node
{
int data;
Node * link;
}
思想:用2个指针 1个步进一 1个步进2 如果存在环 慢指针 必定能追上快指针
bool check(const Node * head)
{
Node * low=head; Node * fast=head->link->link;
while(low!=NULL&&fast!=NULL){
if(low==fast) return true;
}
return false;
}
class Node
{
int data;
Node * link;
}
思想:用2个指针 1个步进一 1个步进2 如果存在环 慢指针 必定能追上快指针
bool check(const Node * head)
{
Node * low=head; Node * fast=head->link->link;
while(low!=NULL&&fast!=NULL){
if(low==fast) return true;
}
return false;
}