// 60ms
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 // Start typing your C/C++ solution below 13 // DO NOT write int main() function 14 ListNode temp(0); 15 ListNode *q,*p; 16 17 18 q=&temp; 19 q->next=head; 20 p=head; 21 22 while(p) 23 { 24 if(p->next&&p->val==p->next->val) 25 { 26 while(p->next&&p->val==p->next->val) 27 { 28 p->next=p->next->next; 29 q->next=p->next; 30 } 31 } 32 else 33 { 34 q=p; 35 } 36 p=p->next; 37 } 38 return temp.next; 39 } 40 };