Sunny-117 / js-challenges

✨✨✨ Challenge your JavaScript programming limits step by step

Home Page:https://juejin.cn/column/7244788137410560055

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

环形链表 II

Sunny-117 opened this issue · comments

/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var detectCycle = function(head) {
    let cur = head;
    while(cur){
        if(cur.dirty){
            return cur;
        }
        cur.dirty = true; //打个标记
        cur = cur.next;
    }
    return null
};