Created
December 17, 2019 21:28
-
-
Save rahul4coding/b8f42fb2bf58ce0a8d349af4b73befe3 to your computer and use it in GitHub Desktop.
Find merge point of two linked list | JS
This file contains 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