We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I think this solution I found here is pretty genius. You just sinc the two list iterators by connecting the ends of each list to the beginning of the next list:
int FindMergeNode(Node headA, Node headB) {
Node currentA = headA;
Node currentB = headB;
//Do till the two nodes are the same
while(currentA != currentB){
//If you reached the end of one list start at the beginning of the other one
//currentA
if(currentA.next == null){
currentA = headB;
}else{
currentA = currentA.next;
}
//currentB
if(currentB.next == null){
currentB = headA;
}else{
currentB = currentB.next;
}
}
return currentB.data;
}
Find Merge Point of Two Lists
You are viewing a single comment's thread. Return to all comments →
I think this solution I found here is pretty genius. You just sinc the two list iterators by connecting the ends of each list to the beginning of the next list: