查看: 66|回复: 0

142.环形链表 II

[复制链接]

1

主题

0

回帖

0

积分

积极分子

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2008-2-1
发表于 2025-11-3 18:57:00 | 显示全部楼层 |阅读模式
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
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部