My c++ sulotion

  • 0
    bool hasCycle(ListNode *head) {
        ListNode* l1=head;
        ListNode* l2=head;
        while(l1 != NULL && l2 != NULL)
            l1= l1->next;
            ListNode* tmp = l2->next;
            if(tmp == NULL)
                return false;
            l2= tmp->next;
            if(l1== l2)
                return true;
        return false;

Log in to reply

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