【leetcode】82. 删除排序链表中的重复元素 II

 

struct ListNode* deleteDuplicates(struct ListNode* head){
    int cnt=0;
    struct ListNode* root=(struct ListNode*)calloc(sizeof(struct ListNode),1);
    struct ListNode* cur=root;
    root->next=head;
    while(head){
        cnt++;
        if(head->next==NULL || head->next->val!=head->val){
            if(cnt<2){
                cur->next=head;
                cur=head;                
            }            
            cnt=0;
        }
        head=head->next;
    }
    cur->next=NULL;
    return root->next;
}

 

posted @ 2020-12-13 17:20  温暖了寂寞  阅读(56)  评论(0编辑  收藏  举报