Skip to content

Instantly share code, notes, and snippets.

@code4sharing
Created August 12, 2015 11:05
Show Gist options
  • Save code4sharing/363a4651be5209646aef to your computer and use it in GitHub Desktop.
Save code4sharing/363a4651be5209646aef to your computer and use it in GitHub Desktop.
Find merge point between two linkedlist
/*
Insert Node at the end of a linked list
head pointer input could be NULL as well for empty list
Node is defined as
class Node {
int data;
Node next;
}
*/
int FindMergeNode(Node headA, Node headB) {
// Complete this function
// Do not write the main method.
Node tempB=new Node();
while(headA!=null)
{
tempB=headB;
while(tempB!=null)
{
if(headA==tempB)
{
return tempB.data;
}
tempB=tempB.next;
}
headA=headA.next;
}
return headA.data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment