My diffrent solution


  • -1
    O

    bool hasCycle(ListNode head) {
    ListNode
    p=head;enter code here
    while(p)
    {
    if(p->val==-100)
    return true;
    p->val=-100;
    p=p->next;
    }
    return false;
    }


  • 0
    R

    This is just a way to get pass the given test cases.

    However, what if I give you the input (-100) -> (-100) -> (-100), this will definitely fail.


Log in to reply
 

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