很水的一道题,两个指针关系处理好就行。
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* deleteDuplicates(struct ListNode* head) {
struct ListNode * p, * q;
p = head;
while(p != NULL)
{
q = p -> next;
if(q == NULL)
break;
if(p -> val == q -> val)
{
p -> next = q -> next;
}
else
p = q;
}
return head;
}