-
-
Save Preetiraj3697/a9ea7a84d969eb44a0dc6a5f6c276c45 to your computer and use it in GitHub Desktop.
Find merge point of two linked list | JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Find Merge point of Two linked list