#include <stdbool.h>
bool hasCycle(struct ListNode* head ) {
if(head == NULL)
return NULL;
struct ListNode* fast = head;
struct ListNode* slow = head;
while(fast != NULL && fast->next != NULL)
{
fast = fast->next->next;
slow = slow->next;
if(fast == slow)
return true;
}
return false;
}

京公网安备 11010502036488号