[leetcode] 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 {//on my own
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode* cur=head;
        ListNode* ret1=head;
        while(cur){
            while(cur->next!=NULL && cur->val==cur->next->val){
                cur=cur->next;
            }
            ret1->next=cur->next;
            ret1=cur->next;
            cur=cur->next;
        }
        return head;
    }
};
原文地址:https://www.cnblogs.com/whutqueqiaoxian/p/5657356.html