#include <stdio.h>
#include <stdbool.h>
struct ListNode {
int val;
struct ListNode* next;
};
typedef struct ListNode ListNode;
bool hasCycle(ListNode* head) {
ListNode* slow = head, * fast = head;
while (fast && fast->next) {
slow = slow->next;
fast = fast->next->next;
if (slow == fast) {
return true;
}
}
return false;
}
【LeetCode】141. 环形链表
最新推荐文章于 2024-09-07 10:12:58 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)