Given a sorted linked list, delete all duplicates such that each element appear only once.
Example 1:
Input: 1->1->2 Output: 1->2
Example 2:
Input: 1->1->2->3->3 Output: 1->2->3
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* deleteDuplicates(struct ListNode* head) {
if(head==NULL||head->next==NULL)
return head;
struct ListNode *p,*q;
p=head;
while(p->next!=NULL)
{
if(p->val==p->next->val)
p->next=p->next->next;
else
p=p->next;
}
return head;
}