Runtime Error.Please help me && Thanks a lot!


  • 0
    X
    bool hasCycle(struct ListNode *head) {
        if((head==NULL)||(head->next==NULL)) 
            return false;
        struct ListNode *temp,*node;
        node=head;
        while(node){
            if(node->next==head) return true;
            temp=node->next;
            node->next=head;
            node=temp;
        }
        return false;
    }
    
    Last executed input:
    [1,2]
    no cycle
    

Log in to reply
 

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