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

相交链表

Sunny-117 opened this issue · comments

commented
/**
 * @param {ListNode} headA
 * @param {ListNode} headB
 * @return {ListNode}
 */
var getIntersectionNode = function(headA, headB) {
    let cur1 = headA;
    let cur2 = headB;

    while(cur1 || cur2){
        if(cur1){
            if(cur1.dirty){
                return cur1
            }
            cur1.dirty = true; //打个标记
            cur1 = cur1.next;
        }
        if(cur2){
             if(cur2.dirty){
                return cur2
            }
            cur2.dirty = true
            cur2 = cur2.next;
        }
    }
    return null
};