题解 | #删除有序链表中重复的元素-I#
删除有序链表中重复的元素-I
https://www.nowcoder.com/practice/c087914fae584da886a0091e877f2c79
#include <stdlib.h>
struct ListNode* deleteDuplicates(struct ListNode* head ) {
if(!head || !head->next)
{
return head;
}
struct ListNode *temp,*pre;
temp = head->next;
pre = head;
int flag = 0;
while(temp)
{
if (temp->val==pre->val) {
temp = temp->next;
free(pre->next);
pre->next = temp;
}
else {
pre = temp;
temp=temp->next;
}
}
return head;
}
查看15道真题和解析
小天才公司福利 1165人发布
