注意考慮下特殊情況,即什麼時候返回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;
};