删除链表中重复节点(设一个前驱节点找到重复节点后删除)
删除链表中重复的结点
http://www.nowcoder.com/questionTerminal/fc533c45b73a41b0b44ccba763f866ef
class Solution { public: ListNode* deleteDuplication(ListNode* pHead) { ListNode *vhead = new ListNode(-1); vhead->next = pHead; ListNode *pre = vhead, *cur = pHead; while (cur) { if (cur->next && cur->val == cur->next->val) { cur = cur->next; while (cur->next && cur->val == cur->next->val) { cur = cur->next; } cur = cur->next; pre->next = cur; } else { pre = cur; cur = cur->next; } } return vhead->next; } };