leetcode/141.c
2024-09-08 14:39:20 +08:00

27 lines
426 B
C

#include "include/ListNode.h"
#include <stdbool.h>
bool hasCycle(struct ListNode *head)
{
if (!head || !head->next)
return false;
struct ListNode *slow = head;
struct ListNode *fast = head->next;
while (slow != fast)
{
if (!fast || !fast->next)
return false;
slow = slow->next;
fast = fast->next->next;
}
return true;
}
int main()
{
return 0;
}