Created
May 10, 2016 22:11
-
-
Save stevensona/a8a71f58a9db853c1f28ff676e7a6411 to your computer and use it in GitHub Desktop.
remove duplicates from sorted linked list
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
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