注意考虑下特殊情况,即什么时候返回null(链表长度为0或1或压根无环)
var detectCycle = function(head) {
if(head===null||head.next===null) return null;
let fast=head,slow=head;
do{
if(fast.next===null||fast.next.next===null) return null;
fast=fast.next.next;
slow=slow.next;
}while(fast!==slow)
fast=head;
while(fast!==slow){
fast=fast.next;
slow=slow.next;
}
return fast;
};