题解 | #删除有序链表中重复的元素-I#
删除有序链表中重复的元素-I
https://www.nowcoder.com/practice/c087914fae584da886a0091e877f2c79
#include <stdlib.h>
struct ListNode* deleteDuplicates(struct ListNode* head ) {
    if(!head || !head->next)
    {
        return head;
    }
    struct ListNode *temp,*pre;
    temp = head->next;
    pre = head;
    int flag = 0;
    while(temp)
    {
        if (temp->val==pre->val) {
            temp = temp->next;
            free(pre->next);
            pre->next = temp;
        }
        else {
            pre = temp;
            temp=temp->next;
        }
    }
    return head;
}
 查看11道真题和解析
查看11道真题和解析