[Leetcode] (141 circular linked list)

Insert picture description here

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;
}


Guess you like

Origin blog.csdn.net/qq_45657288/article/details/108983275