83. Remove Duplicates from Sorted List
程序员文章站
2022-07-14 08:40:34
...
图解分析
当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实现代码
推荐阅读
-
【一天一道LeetCode】#26. Remove Duplicates from Sorted Array
-
LeetCode 83. Remove Duplicates from Sorted List
-
83. Remove Duplicates from Sorted List
-
LeetCode 83. Remove Duplicates from Sorted List
-
LeetCode 83. Remove Duplicates from Sorted List ***
-
Leetcode 83. Remove Duplicates from Sorted List
-
Remove Nth Node From End of List(C++)
-
Leetcode No.26 Remove Duplicates from Sorted Array(c++实现)
-
26. Remove Duplicates from Sorted Array
-
【LeetCode】80. Remove Duplicates from Sorted Array II (删除排序数组中的重复项 II)-C++实现及详细图解