/*赋值解法*/
bool hasCycle(struct ListNode *head) { 
    while(head)
    {
        if (head->val == 1000000) return true;
        head->val=1000000;
        head=head->next;
    }
    return false;
}

 

 //使用快慢指针法
bool hasCycle(struct ListNode *head) 
{
    struct ListNode *fast=head,*slow=head;
    while((fast)!=NULL && (fast->next)!=NULL)
    {
        fast=fast->next->next;
        slow=slow->next;
        if(fast==slow)
        {
            return true;
        }
    }
    return false;
}