Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.
这个就比较简单了。。。
ListNode *deleteDuplicates(ListNode *head)
{
if(head==NULL)
return NULL;
ListNode *newq=head;
ListNode *root=newq;
while(head->next!=NULL)
{
if(head->next->val!=head->val)
{
newq->next=head->next;
newq=newq->next;
}
head=head->next;
}
newq->next=NULL;
return root;
}