An easy


  • 0
    H
     public boolean hasCycle(ListNode head) {
        if(head == null || head.next==null)
            return false;
         ListNode h = head;
         ListNode temp; 
         while(head.next != h && head.next!=null){
             temp = head;
             head = head.next;
             temp.next = h;
         }
         if(head.next == h) return true;
         return false;
     }

Log in to reply
 

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