Shu-How Zの小窝

Loading...

142.环形链表 II

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;
};
posted @ 2025-11-03 18:57  KooTeam  阅读(2)  评论(0)    收藏  举报