题解 | #删除有序链表中重复的元素-I#
删除有序链表中重复的元素-I
https://www.nowcoder.com/practice/c087914fae584da886a0091e877f2c79
struct ListNode* deleteDuplicates(struct ListNode* head ) {
// write code here
struct ListNode *pre,*nxt;
if(head==NULL||head->next==NULL)
return head;
pre=head;
nxt=pre->next;
while(nxt!=NULL)
{
if(pre->val==nxt->val)
{
pre->next=nxt->next;
free(nxt);
nxt=pre->next;
}
else
{
pre=pre->next;
nxt=nxt->next;
}
}
return head;
}
查看15道真题和解析
