相交链表
Sunny-117 opened this issue · comments
/**
* @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
};