Why my solution is wrong?


  • 0
    W
     public boolean hasCycle(ListNode head) {
            if (head == null) { return false; }
            else {
                ListNode ptr = head.next;
                while(ptr != null){
                    if (ptr == head) return true;
                    ptr = ptr.next;
                }
                return false;
            }
        }
    

Log in to reply
 

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