Skip to content

Instantly share code, notes, and snippets.

@rahul4coding
Created December 17, 2019 21:28
Show Gist options
  • Save rahul4coding/b8f42fb2bf58ce0a8d349af4b73befe3 to your computer and use it in GitHub Desktop.
Save rahul4coding/b8f42fb2bf58ce0a8d349af4b73befe3 to your computer and use it in GitHub Desktop.
Find merge point of two linked list | JS
function findMergeNode(headA, headB) {
let currentA = headA;
let currentB = headB;
while(currentA!==currentB){
//headA
if(currentA.next==null){
currentA.next=headB
}else{
currentA = currentA.next
}
// headB
if(currentB.next==null){
currentB.next=headA;
}else{
currentB = currentB.next;
}
}
return currentA.data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment