Skip to content

Instantly share code, notes, and snippets.

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/a13738b4ab32decb8601f29777172209 to your computer and use it in GitHub Desktop.
Save jianminchen/a13738b4ab32decb8601f29777172209 to your computer and use it in GitHub Desktop.
HackerRank - delete duplicate value nodes from a sorted linked list - most favorite solution
/*
Remove all duplicate elements from a sorted linked list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
Node* RemoveDuplicates(Node *head)
{
Node *cur = head;
int last_seen = cur->data;
while(cur->next) {
if(cur->next->data == last_seen) {
cur->next = cur->next->next;
}else {
cur = cur->next;
last_seen = cur->data;
}
}
return head;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment