var detectCycle = function(head) {
if(!head)return null;
let pre=head,cur=head;
while(cur&&cur.next){
pre=pre.next;
cur=cur.next.next;
if(pre===cur){
let temp=head;
while(temp!==pre){
pre=pre.next;
temp=temp.next;
}
return pre
}
}
return null;
};
来源:https://www.cnblogs.com/KooTeam/p/19187963 |