83. Remove Duplicates from Sorted List

来源:互联网 发布:惠州网络车问政平台 编辑:程序博客网 时间:2024/06/15 01:37

这里写图片描述
图解分析
当p_current->val==p_next->val
这里写图片描述
当p_current->val!=p_next->val :p_current指针向前移动
这里写图片描述

C实现代码如下:

/** * Definition for singly-linked list. * struct ListNode { *     int val; *     struct ListNode *next; * }; */
struct ListNode *deleteDuplicates(struct ListNode *head){    if(head==NULL) return head;    struct ListNode *p_current=head;    struct ListNode *p_next=head->next;    While(p_current!=NULL&&p_next!=NULL){        if(p_current->val==p_next->val)            p_current->next=p_next->next;        else            p_current=p_next;        p_next=p_next->next;        }    return head;}

LeetCode实现代码
这里写图片描述

原创粉丝点击