//快慢指針 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; } }