You are viewing a single comment's thread. Return to all comments →
solution with JS
function findMergeNode(headA, headB) { let current1 = headA; let current2 = headB; let length1 = 0; let length2 = 0; while (current1) { length1++; current1 = current1.next; } while (current2) { length2++; current2 = current2.next; } current1 = headA; current2 = headB; if (length1 > length2) { for (let i = 0; i < length1 - length2; i++) { current1 = current1.next; } } else if (length2 > length1) { for (let i = 0; i < length2 - length1; i++) { current2 = current2.next; } } while (current1 && current2) { if (current1 === current2) { return current1.data; } current1 = current1.next; current2 = current2.next; } return null; }
Seems like cookies are disabled on this browser, please enable them to open this website
Find Merge Point of Two Lists
You are viewing a single comment's thread. Return to all comments →
solution with JS