第7讲7*
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* deleteDuplication(ListNode* head) {
auto dummy = new ListNode(-1);
dummy->next = head;
auto p = dummy;
while(p->next)
{
auto q = p->next;
while(q->next && q->next->val == p->next->val) q = q->next;
if(q == p->next) p = q;
else p->next = q->next;
}
return dummy->next;
}
};
// 1->2->3->3->4->4->5
//s->1->2->3->3->4->4->5
//p q
// m n m!=n
// p q
// p q
// m n m = n
// p q
//s->1->2 ->4->4->5
//......