If the next node is not checked null after 10000 times, there is a circle.


  • 0
    Y
    public class Solution {
    public boolean hasCycle(ListNode head) {
        if(head == null)
            return false;
        int i = 0;
        while(head.next != null){
            i++;
            if (i > 10000){
                return true;
            }
            head = head.next;
        }
        return false;
    }
    

    }

    Is this a opportunism?


  • 0
    S

    Of course it is cheated. just avoid the test cases.


Log in to reply
 

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