83. Remove Duplicates from Sorted List

/**
 * 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) {
        if (head == NULL)   return head;
        ListNode* p = head;
        while (p->next) {
            if (p->next->val == p->val) {
                ListNode* t = p->next;
                p->next = t->next;
                delete t;
            }
            else
                p = p->next;
        }
        return head;
    }
};
原文地址:https://www.cnblogs.com/JTechRoad/p/10012341.html