class HasCycleInLinkedList{
public boolean hasCycle(ListNode head){
if(head == null || head.next == null) return false;
if(head.next == head) return true; ListNode nextNode = head.next;
head.next = head;
boolean isCycle = hasCycle(nextNode);
return isCycle;
}
}
public boolean hasCycle(ListNode head){
if(head == null || head.next == null) return false;
if(head.next == head) return true; ListNode nextNode = head.next;
head.next = head;
boolean isCycle = hasCycle(nextNode);
return isCycle;
}
}