Skip to content

Instantly share code, notes, and snippets.

@Preetiraj3697
Forked from rahul4coding/findMergeNode.js
Created October 21, 2022 05:39
Show Gist options
  • Save Preetiraj3697/a9ea7a84d969eb44a0dc6a5f6c276c45 to your computer and use it in GitHub Desktop.
Save Preetiraj3697/a9ea7a84d969eb44a0dc6a5f6c276c45 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;
}
@Preetiraj3697
Copy link
Author

Find Merge point of Two linked list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment