博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
leetcode : Remove Duplicates from Sorted List II [基础]
阅读量:4677 次
发布时间:2019-06-09

本文共 1131 字,大约阅读时间需要 3 分钟。

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.

 

tag : dummy node + tmp 

 

/** * Definition for singly-linked list. * public class ListNode { *     int val; *     ListNode next; *     ListNode(int x) { val = x; } * } */public class Solution {    public ListNode deleteDuplicates(ListNode head) {        if(head == null || head.next == null) {            return head;        }        ListNode dummy = new ListNode(0);        dummy.next = head;        head = dummy;                while(head.next != null && head.next.next != null) {            if(head.next.val == head.next.next.val) {                int tmp = head.next.val;                while(head.next != null && (head.next.val == tmp)) {                    head.next = head.next.next;                }            } else {                head = head.next;            }        }        return dummy.next;        }}

  

转载于:https://www.cnblogs.com/superzhaochao/p/6516677.html

你可能感兴趣的文章
pythong中的全局变量的调用和嵌套函数中变量的使用
查看>>
【POJ - 3009】Curling 2.0 (dfs+回溯)
查看>>
Windows下载安装良心教程
查看>>
浅析商业银行“业务连续性管理体系”的构建
查看>>
【分享】从《水浒传》中反思什么是真正的执行力
查看>>
java中的static
查看>>
5.侧边栏逻辑
查看>>
评论博客
查看>>
用户代理字符串识别工具源码与slf4j日志使用
查看>>
算法导论第6部分图算法,第22章图的基本算法
查看>>
提示框第三方库之MBProgressHUD
查看>>
C语言 10-字符和字符串常用处理函数
查看>>
C++ 表达式语句 海伦的故事
查看>>
32位汇编学习笔记(1)
查看>>
day_01
查看>>
2013年12月日本語能力試験N3聴解部分
查看>>
uva 1349(拆点+最小费用流)
查看>>
关于SessionFactory的不同实现类分别通过getCurrentSession()方法 和 openSession() 方法获取的Session对象在保存对象时的一些区别...
查看>>
Web开发细节搜集
查看>>
织梦kindeditor图片上传增加图片说明alt属性和title属性
查看>>