LeetCode 83 Remove Duplicates from Sorted List

LeetCode 83 Remove Duplicates from Sorted List

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* deleteDuplicates(struct ListNode* head) {
    if(head==NULL || head->next==NULL)
        return head;
    struct ListNode* p = head;
    while(p&&p->next)
    {
        if(p->val == p->next->val)
        {
            struct ListNode *tmp = p->next;
            p->next=p->next->next;
            free(tmp);
        }
        else p=p->next;
    }
    return head;
}
原文地址:https://www.cnblogs.com/walker-lee/p/4970892.html