Why it has runtime error , it works well in compilers


  • 0
    C

    public static boolean hasCycle(ListNode head) {
    ListNode ln=head;
    while(true){
    if(ln==null)
    return false;
    else{
    ListNode l=head;
    while(true){
    if(l==ln.next){
    return true;
    }
    else if(l==ln)
    break;
    else
    l=l.next;
    }
    }
    ln=ln.next;
    }
    }


  • 0
    C

    I'v solved it yet, I rewrited the ListNode class defination repeatedly.


Log in to reply
 

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