独立写过
/**
* 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 *tail = head;
while(head){
head = head->next;
if(tail == nullptr || tail->next == nullptr)return false;
tail = tail->next->next;
if(head == tail) return true;
}
return false;
}
};