leetcode 83删除排序链表中的重复元素

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode *pre, *cur, *ahead;
        ahead=pre=new ListNode(-1);cur=head;
        while(cur!=NULL){
            while(cur->next!=NULL && cur->val==cur->next->val){
                cur=cur->next;
            }
            pre->next=cur;
            pre=cur;
            cur=cur->next;
        }
        return ahead->next;
    }
};

原文地址:https://www.cnblogs.com/joelwang/p/11017565.html