2019-09-26 23:29:31 +08:00
|
|
|
struct ListNode* deleteDuplicates(struct ListNode* head) {
|
2019-10-12 18:10:42 +08:00
|
|
|
if (head == NULL)
|
2019-09-26 23:29:31 +08:00
|
|
|
return NULL;
|
2019-10-12 18:10:42 +08:00
|
|
|
|
|
|
|
if (head->next && head->val == head->next->val) {
|
2019-09-26 23:29:31 +08:00
|
|
|
/* Remove all duplicate numbers */
|
2019-10-12 18:10:42 +08:00
|
|
|
while (head->next && head->val == head->next->val) {
|
2019-09-26 23:29:31 +08:00
|
|
|
head = head -> next;
|
2019-10-12 18:10:42 +08:00
|
|
|
}
|
2019-09-26 23:29:31 +08:00
|
|
|
return deleteDuplicates(head->next);
|
|
|
|
} else {
|
|
|
|
head->next = deleteDuplicates(head->next);
|
|
|
|
}
|
|
|
|
return head;
|
|
|
|
}
|