Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

相交链表 #292

Open
Sunny-117 opened this issue Nov 8, 2022 · 1 comment
Open

相交链表 #292

Sunny-117 opened this issue Nov 8, 2022 · 1 comment

Comments

@Sunny-117
Copy link
Owner

No description provided.

@lxy-Jason
Copy link
Contributor

/**
 * @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
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants