![Linked List Cycle (java) Linked List Cycle (java)](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
public boolean hasCycle(ListNode head)
{
ListNode slow=head;
ListNode fast=head;
if(head==null)return false;
while(fast.next!=null)
{
if(fast.next.next==null)return false;
slow=slow.next;
fast=fast.next.next;
if(slow==fast)return true;
}
return false; }