/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
bool hasCycle(struct ListNode *head) {
if(head==NULL||head->next==NULL)
return false;
struct ListNode *slow=head;
struct ListNode *quick=head->next;
while(quick!=NULL&&quick->next!=NULL)
{
slow=slow->next;
quick=quick->next->next;
if(slow==quick)return true;
}
return false;
}
[添加链接描述](https://leetcode-cn.com/problems/linked-list-cycle/solution/yi-wen-gao-ding-chang-jian-de-lian-biao-wen-ti-h-2/)
相关文章
- 12-02Linked List Cycle 判断一个链表是否存在回路(循环)
- 12-02[LeetCode] 141. Linked List Cycle 单链表判圆算法
- 12-02【Leetcode】141. 环形链表(Linked List Cycle)
- 12-02LeetCode 141. Linked List Cycle--百度面试编程题--C++,Python解法
- 12-02【双指针】141. 环形链表(三种方法:单指针,双指针,集合哈希)
- 12-02141. Linked List Cycle【easy】
- 12-02141 Linked List Cycle(判断链表是否有环Medium)
- 12-02LeetCode 141. Linked List Cycle(判断链表是否有环)
- 12-02[Leetcode] Linked list cycle 判断链表是否有环
- 12-02141. Linked List Cycle(判断链表是否有环)