# [leetcode] 【链表】 82. Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.

For example,
Given 1->2->3->3->4->4->5, return 1->2->5.

Given 1->1->1->2->3, return 2->3.

# 题意

Given 1->2->3->3->4->4->5, return 1->2->5.

Given 1->1->1->2->3, return 2->3.

# 题解

/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
while(cur)
{
bool isDuplicate=false;
while(cur->next!=NULL&&cur->val==cur->next->val)
{
isDuplicate=true;
ListNode *temp=cur;
cur=cur->next;
delete temp;
}
if(isDuplicate)
{
ListNode *temp=cur;
cur=cur->next;
prev->next=cur;
delete temp;
}
else
{
prev=prev->next;
cur=cur->next;
}
}
}
};

• 本文已收录于以下专栏：

## LeetCode 82 Remove Duplicates from Sorted List II（从已排序链表中移除重复元素）（Linked List）（*）

• NoMasp
• 2016-08-11 20:25
• 1412

## leetcode 82. Remove Duplicates from Sorted List II （线性表）

leetcode 82. Remove Duplicates from Sorted List IIGiven a sorted linked list, delete all nodes that ...

## LeetCode82:Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct num...

## [leetcode 82]Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb...

## [leetcode] 82. Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb...

## [LeetCode]82.Remove Duplicates from Sorted List II

【题目】 Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distin...

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)