Linked List Cycle

//快慢指针

public class Solution {
public boolean hasCycle(ListNode head) {
if(head==null)return false;
ListNode slow=head;
ListNode fast=head;
do{
if(fast==null||fast.next==null)return false;
fast=fast.next.next;
slow=slow.next;
} while(fast!=slow);
return true;
}
}
原文地址:https://www.cnblogs.com/gaoxiangde/p/4379843.html