ListNode *deleteDuplicates(ListNode *head) {
if (!head) return head;
ListNode *cur = head;
while (cur->next)
{
if (cur->val == cur->next->val)
{
ListNode *del = cur->next;
cur->next = del->next;
delete del;
}
else
{
cur = cur->next;
}
}
return head;
}
No comments:
Post a Comment