# Leetcode - Remove Duplicates from Sorted List II

violet posted @ Aug 15, 2020 07:22:21 AM in 算法 with tags Algorithm Linked List java , 11027 阅读

https://leetcode.com/problems/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.

Return the linked list sorted as well.

Example 1:

```Input: 1->2->3->3->4->4->5
Output: 1->2->5
```

Example 2:

```Input: 1->1->1->2->3
Output: 2->3
```

```/**
* public class ListNode {
*     int val;
*     ListNode next;
*     ListNode() {}
*     ListNode(int val) { this.val = val; }
*     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
ListNode dummy = new ListNode();
ListNode prev = dummy;

while (node != null) {
while (node.next != null && node.val == node.next.val) {
node = node.next;
}
if (prev.next == node) {
prev = prev.next;
} else {
prev.next = node.next;
}
node = node.next;
}
return dummy.next;
}
}```
rasmika 说:
Sep 15, 2021 05:41:35 PM

I found this one pretty enthralling, and you should go into my get-together also.
We give math homework help associations beginning with one side of the planet then onto the going with. I'm stunned by your article. We like that obligingly keep on making more substance.

Karnataka 8th Model 说:
Sep 21, 2022 02:39:21 PM

KSEEB Question Paper 2023 Pdf Download for Karnataka 6th, 7th, 8th, 9th Class Model Paper 2023 Pdf with Answer Solutions for Kannada Medium, English Medium General and Vocational Course Mathematics, Science, Social Science (EVS), English, Kannada, Hindi and etc. Karnataka State Board High School Education Class 6th, 7th, 8th and 9th Standard Kannada Medium, English Medium Question Paper with answer solutions download for theory, Karnataka 8th Model Paper objective type multiple choice questions (MCQ) for KSEEB conducted general and vocational course SA, FA, Unit Tests, Quarterly, Half-yearly, Pre- Final and annual final public examination tests to the academic year of 2023.

Ankitasingh 说:
Dec 26, 2022 09:14:40 PM

I see your post and read. This is good for me this is a good post you give a piece of great information and helpful thanks for sharing this page. [url=https://redpah.com/profile/337738/swatisingh]South Delhi Escorts Service[/url]
[url=https://dev.funkwhale.audio/swatisingh]Escorts in South Delhi[/url]
[url=https://riuso.comune.salerno.it/swatisingh]South Delhi Escorts[/url]
[url=https://k289gitlab1.citrin.ch/swatisingh]Escorts Service in South Delhi[/url]
[url=https://forum.bela.io/u/swatisingh]South Delhi Escort[/url]
[url=https://peatix.com/user/14014474/view]South Ex Escorts Service[/url]
[url=https://git.disroot.org/swatisingh]Escorts in South Ex[/url]
[url=https://www.jigsawplanet.com/swatisingh?viewas=3396cc55b692]South Ex Escorts[/url]
[url=https://www.myminifactory.com/users/swatisingh]Escorts Service in South Ex[/url]
[url=https://longbets.org/user/swatisingh/]South Ex Escort[/url]
[url=https://jomkerja.my/author/swati-singh/]Karol Bagh Escorts Service[/url]
[url=https://vapenews.ru/profile/swatisingh/]Escorts in Karol Bagh[/url]
[url=https://kktix.com/user/3703141]Karol Bagh Escort[/url]
[url=https://vocal.media/authors/swatisingh]Escort in Karol Bagh[/url]
[url=https://live-for-less.mn.co/members/13266593]Agra Escorts Service[/url]
[url=https://englishclub.mn.co/members/13266792]Escorts in Agra[/url]
[url=https://www.moonshineink.com/user/swati-singh/?profiletab=main]Agra Escorts[/url]