A java Implementation, does anybody know what is "Last executed input: {}, no cycle" mean?


  • 0
    Y

    I also use the idea of faster and slower runner, I get a running error on OJ,here is my code:
    I'm not sure what's the reason......

    public class Solution {

    public boolean hasCycle(ListNode head) {

        ListNode slow, fast;
    
       if(head==null) return false;
       if (head.next == null) return false;
        slow = head;
        fast = slow.next;
    
       while( fast!=null && fast.next!=null){
    
           if (slow == fast ||fast.next == slow){
               return true;
           } 
            
            else{
            slow = slow.next;
            fast = fast.next.next;
            }
        }
        return false;
        
    }
    

    }


  • 1
    S

    This code can be accepted as-is. That error message can be triggered when you failed to handle the situation when the linked list is empty, but it is already taken care of in your code.


  • 0
    Y

    thx, it also works well in eclipse


Log in to reply
 

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