How about this 6ms solution... :)


  • 0
    T

    How about this 6ms solution... :)

    bool hasCycle(struct ListNode *head) {
        struct ListNode * p = 0;
        int i;
        
        if(head==NULL) 
            return false;
        
        p = head;
        
        for (i = 0; i < 9000; i++) {
            if (p->next == NULL) break;
            p = p->next;
        }
    
        if (i >= 9000) return true;
        else return false;
        
    }
    

Log in to reply
 

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