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) {
        ListNode *root=head;
        while(head!=NULL)
        {
            while(head->next!=NULL&&head->val==head->next->val)
            {
                head->next=head->next->next;
            }
            head=head->next;
        }
        return root;
    }
};
原文地址:https://www.cnblogs.com/smallredness/p/10676005.html