标签:
鉴于一个列表,推断该列表环的存在。
bool hasCycle(ListNode *head) {
if(head == NULL)
return false;
ListNode *fast = head;
ListNode *slow = head;
while(NULL != fast && NULL != fast->next)
{
fast = fast->next->next;
slow = slow->next;
if(slow == fast)
return true;
}
return false;
}版权声明:本文博客原创文章,博客,未经同意,不得转载。
标签:
原文地址:http://www.cnblogs.com/yxwkf/p/4742973.html