The key of this problem is about details especially boundary conditions.
class Solution { public: ListNode *deleteDuplicates(ListNode *head) { if(!head) return NULL; ListNode *p = head; ListNode *p0 = p->next; while(p && p0) { while(p && p0 && p->val == p0->val) { p->next = p0->next; p0 = p0->next; } p = p0; if(p0) p0 = p0->next; } return head; } };