删除一个链表上的重复的数字。
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
ListNode* first;
ListNode* second;
first=head;
if(head==NULL)return head;
second=first->next;
if(second==NULL)return head;
ListNode* temp;
while(second!=NULL){
if(first->val==second->val){
temp=second;
first->next=second->next;
delete temp;
second=first->next;
//second=second->next;
//first=first->next;
}
else{
second=second->next;
first=first->next;
}
}
return head;
}
};