题解 | #删除有序链表中重复的元素-I#
删除有序链表中重复的元素-I
https://www.nowcoder.com/practice/c087914fae584da886a0091e877f2c79
struct ListNode* deleteDuplicates(struct ListNode* head)
{
if(head == NULL)
{
return head;
}
struct ListNode* p = head;
while(p->next != NULL)
{
if(p->val == p->next->val) //相邻数据相等时
{
p->next = p->next->next;//相等的数据的第一个的指针指向不相等的数据元素
}
else
{
p = p->next;
}
}
return head;
}
