Skip to content

Instantly share code, notes, and snippets.

@miniharryc
Created April 9, 2016 21:03
Show Gist options
  • Save miniharryc/f2940937a34eb901a6c65dddab4f3de6 to your computer and use it in GitHub Desktop.
Save miniharryc/f2940937a34eb901a6c65dddab4f3de6 to your computer and use it in GitHub Desktop.
HackerRank compare two linked lists
/*
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)
{
Node *a = headA, *b = headB;
while( a && b && ( a->data == b->data ) ) {
a = a->next;
b = b->next;
}
return a == b; //both are null pointers
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment