141. Linked List Cycle(双指针)

/**
 * 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/)

上一篇:「SOL」Hamiltonian Cycle (AtCoder)


下一篇:痞子衡嵌入式:同一厂商不同系列Flash型号下Dummy Cycle设置方法可能有差异 (以IS25LP064为例)