var detectCycle = function(head) {
// if(!head)return null;
// if(!head.next)return null;
let f=new ListNode();
let s=new ListNode();
f=head;
s=head;
while(true){
if(f==null ||f.next==null)return null;
f=f.next.next;
s=s.next
//第一次相遇
if(f==s)break;
}
f=head;
while(f!=s){
s=s.next;
f=f.next
}
//第二次相遇的时候f已经走了链表入环口
return f
};
08-10
412
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)