/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head ListNode类
* @return ListNode类
*/
struct ListNode* deleteDuplicates(struct ListNode* head )
{
if(head == NULL)
{
return head;
}
struct ListNode* fast=head->next;
struct ListNode* slow=head;
while(fast != NULL)
{
//如果两个结点的值相等
if(fast->val == slow->val)
{
slow->next=fast->next;
free(fast);
fast=slow->next;
}
else //如果不相等
{
fast=fast->next;
slow=slow->next;
}
}
return head;
}