环形链表 循环 快慢指针 - lifengyu360/lifengyu_first_git_test GitHub Wiki
class Solution {
public:
bool hasCycle(ListNode *head) {
if ((head == NULL) || (head->next== NULL)){
return false;
}
ListNode *slow = head;
ListNode *quick = head->next;
while(slow != quick){
if ((slow == NULL) ||(quick==NULL)|| (quick->next == NULL)){
return false;
}
slow = slow->next;
quick=quick->next->next;
}
return true;
}
};