Created
May 8, 2016 18:49
-
-
Save jianminchen/9d14ff515146af193c4bee660b0a6fb8 to your computer and use it in GitHub Desktop.
Find Merge Point - unbelievable short
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
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