Skip to content

Instantly share code, notes, and snippets.

@stevensona
Created May 10, 2016 22:11
Show Gist options
  • Save stevensona/a8a71f58a9db853c1f28ff676e7a6411 to your computer and use it in GitHub Desktop.
Save stevensona/a8a71f58a9db853c1f28ff676e7a6411 to your computer and use it in GitHub Desktop.
remove duplicates from sorted linked list
Node* removeDuplicates(Node *head) {
if(head == nullptr) return head;
while(head->next != nullptr && head->data == head->next->data) {
auto dup = head->next;
head->next = dup->next;
delete dup;
}
removeDuplicates(head->next);
return head;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment