Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created May 8, 2016 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/9d14ff515146af193c4bee660b0a6fb8 to your computer and use it in GitHub Desktop.
Save jianminchen/9d14ff515146af193c4bee660b0a6fb8 to your computer and use it in GitHub Desktop.
Find Merge Point - unbelievable short
int FindMergeNode(Node *headA, Node *headB){
int a=0,b=0;
for(Node *z=headA;z;a++)z=z->next;
for(Node *z=headB;z;b++)z=z->next;
for(;a>b;a--)headA=headA->next;
for(;a<b;b--)headB=headB->next;
for(;headA->data!=headB->data;)headA=headA->next,headB=headB->next;
return headA->data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment