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;
}

京公网安备 11010502036488号