leetcode:
https://blog.youkuaiyun.com/chenxiyuehh/article/details/90241722
offer:
https://blog.youkuaiyun.com/qq_30193419/article/details/93596329
https://blog.youkuaiyun.com/qq_21815981/article/details/79833976(更多例题)
bool HasCircle(Node *head)
{
if(head == NULL)
return false;
Node *slow = head, *fast = head;
while(fast != NULL && fast->next!=NULL)
{
slow = slow->next; //慢指针每次前进一步
fast = fast->next->next;//快指针每次前进两步
if(slow == fast) //相遇,存在环
return true;
}
return false;
}