/**
* 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) {
//if (!head || !head->next) return head;
ListNode *start = new ListNode(0);
ListNode *pre = new ListNode(0);
ListNode *cur = new ListNode(0);
start->next = head;
pre = start;
while(pre->next)
{
cur = pre->next;//作为后继
while(cur->next&&cur->next->val==cur->val)
cur=cur->next;
if(cur!=pre->next)//说明有移动
pre->next = cur->next;
else
pre = pre->next;
}
return start->next;
}
};
82. 删除排序链表中的重复元素 II
最新推荐文章于 2019-12-05 17:23:34 发布