标签:
https://leetcode.com/problems/remove-duplicates-from-sorted-list/
1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 8 */ 9 class Solution { 10 public: 11 ListNode* deleteDuplicates(ListNode* head) { 12 ListNode * temp=NULL; 13 ListNode * tail=NULL; 14 temp=head; 15 while(temp!=NULL) 16 { 17 if(tail!=NULL) 18 { 19 if(tail->val==temp->val) 20 { 21 tail->next=temp->next; 22 temp=tail->next; 23 } 24 else 25 { 26 tail=temp; 27 temp=temp->next; 28 } 29 } 30 else 31 { 32 tail=temp; 33 temp=temp->next; 34 } 35 36 37 } 38 return head; 39 } 40 };
Remove Duplicates from Sorted List
标签:
原文地址:http://www.cnblogs.com/aguai1992/p/4637999.html