Accepted as best submission in C


  • 0
    bool hasCycle(struct ListNode* head)
    {
        if(!head || !head->next) return false;
        struct ListNode *slow=head, *fast=head->next;
        while(fast && fast->next)
        {
            slow = slow->next;
            fast = fast->next->next;
            if(slow == fast)
                return true;
        }
        return false;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.