Leetcode - Plus One Linked List

Leetcode - Remove Duplicates from Sorted List II

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


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


 * Definition for singly-linked list.
 * 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 {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode dummy = new ListNode();
        dummy.next = head;
        ListNode prev = dummy;
        ListNode node = head;
        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.
<a href="https://www.callgirlsdehradunescort.com/haridwar-escorts.html">Haridwar Escorts</a>
<a href="https://www.callgirlsdehradunescort.com/roorkee-escorts.html">Escorts in Roorkee</a>
<a href="https://www.callgirlsdehradunescort.com/haldwani-escorts.html">Haldwani Escorts Service</a>
<a href="https://www.callgirlsdehradunescort.com/chennai-escorts.html">Escorts Service in Chennai</a>
<a href="https://www.callgirlsdehradunescort.com/rishikesh-escorts.html">Rishikesh Escort</a>
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://answerpail.com/index.php/user/swatisingh]Escort in South Delhi[/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://grace-sufficient-ministries.mn.co/posts/about-me-28020789]Escort in South Ex[/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://curlebrity.mn.co/posts/about-me-28023079]Karol Bagh Escorts[/url]
[url=https://spoder.mn.co/posts/about-me-28023504]Escorts Service 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]
[url=https://network-427365.mn.co/posts/about-me-28060411]Escorts Service in Agra[/url]
[url=https://omind.mn.co/posts/about-me-28061396]Agra Escort[/url]
[url=https://one-jam-productions.mn.co/posts/about-me-28063082]Escort in Agra[/url]
[url=https://vhearts.net/Nightangels#gsc.tab=0]Ahmedabad Escorts Service[/url]
[url=https://lyfepal.com/nightangels]Escorts in Ahmedabad[/url]
[url=https://www.geeb.xyz/Nightangels]Ahmedabad Escorts[/url]
[url=https://www.bitrated.com/nightangels]Escorts Service in Ahmedabad[/url]
[url=https://saintjohnvianneysocials.com/NightAngels]Ahmedabad Escort[/url]
[url=https://shapshare.com/NightAngels]Escort in Ahmedabad[/url]

登录 *

loading captcha image...
or Ctrl+Enter