Time limit?why


  • 0
    T

    my code is
    public boolean hasCycle(ListNode head) {
    if(head==null ){
    return false;
    }
    ListNode l1=head;
    ListNode l2=head;
    while(l2.next!=null && l2.next.next!=null){
    l1=l1.next;
    l2=l2.next.next;
    if(l1==l2){
    return true;
    }
    }
    return false;
    }

    it will work, but when the condition is
    if(head==null || head.next==null){
    it will be time limited . I dont know why. Does someone know?


  • 0
    W

    i have the same question.


  • 0
    T

    @wyy19900707
    yeah it's really a strange question.


Log in to reply
 

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