链表-remove duplicates from sorted list

struct ListNode* deleteDuplicates(struct ListNode* head) {
    struct ListNode *p=head;
    if(!head)
        return head;
    while(p&&p->next)
    {
        if(p->val==p->next->val)
            p->next=p->next->next;
        else
            p=p->next;
    }
    
    return head;
    
}

要注意考虑1->1->1这种情况,第一个1要和后面比较多次。

posted on 2016-03-13 16:32  summerkiki  阅读(92)  评论(0编辑  收藏  举报