/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* deleteDuplicates(struct ListNode* head)
{
if(NULL == head)
return NULL;
struct ListNode* p = head;
struct ListNode* q = head->next;
int val1 = p->val;
int val2;
while(q != NULL)
{
val2 = q->val;
if(val2 == val1)
{
q = q -> next;
if(q == NULL)
{
p->next = q;
}
}
else
{
val1 = val2;
p ->next = q;
p = q;
q = q -> next;
}
}
return head;
}
网友评论