/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
bool hasCycle(struct ListNode *head) {
struct ListNode *fast_p=head,*slow_p=head;
while(fast_p!=NULL&&fast_p->next!=NULL){
slow_p=slow_p->next;
fast_p=fast_p->next->next;
if(slow_p==fast_p) {
return true;
}
}
return false;
}
141. 环形链表
最新推荐文章于 2024-12-28 14:19:02 发布
2449

被折叠的 条评论
为什么被折叠?



