Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created May 9, 2016 19:26
Show Gist options
  • Save jianminchen/904a955b78a56ece032f5b9a681f91fc to your computer and use it in GitHub Desktop.
Save jianminchen/904a955b78a56ece032f5b9a681f91fc to your computer and use it in GitHub Desktop.
HackerRank - LinkedList - compare two linked list
/*
Compare two linked lists A and B
Return 1 if they are identical and 0 if they are not.
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
int CompareLists(Node *headA, Node* headB)
{
if(headA==NULL && headB==NULL)
return 1;
if(headA==NULL || headB == NULL)
return 0;
if(headA->data == headB->data)
return CompareLists(headA->next, headB->next);
else
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment