leetcode 83删除排序链表中的重复元素
2020-12-13 01:53
标签:isp 技术 efi one audio img leetcode mic control leetcode 83删除排序链表中的重复元素 标签:isp 技术 efi one audio img leetcode mic control 原文地址:https://www.cnblogs.com/joelwang/p/11017565.html/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
ListNode *pre, *cur, *ahead;
ahead=pre=new ListNode(-1);cur=head;
while(cur!=NULL){
while(cur->next!=NULL && cur->val==cur->next->val){
cur=cur->next;
}
pre->next=cur;
pre=cur;
cur=cur->next;
}
return ahead->next;
}
};