1、题目描述

2、题目分析

链表的题,主要注意指针即可。

3、代码

  ListNode* deleteDuplicates(ListNode* head) {
if (head == NULL || head->next == NULL)
return head; ListNode *dummy = new ListNode();
dummy->next = head;
ListNode *p = head;
ListNode *pre = dummy; while (p != NULL) {
ListNode *tmp = p->next;
if (tmp == NULL)
break;
while (tmp->val == p->val) {
tmp = tmp->next;
if (tmp == NULL) {
pre->next = NULL;
break;
}
} if (p->next == tmp) {
pre = p;
}else {
pre->next = tmp;
}
p = tmp; }
return dummy->next; }

LeetCode 题解之Remove Duplicates from Sorted List II的更多相关文章

  1. leetcode 题解:Remove Duplicates from Sorted Array II(已排序数组去三次及以上重复元素)

    题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...

  2. 【一天一道LeetCode】#80. Remove Duplicates from Sorted Array II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Follow ...

  3. 【LeetCode练习题】Remove Duplicates from Sorted List II

    Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...

  4. 【LeetCode】80. Remove Duplicates from Sorted Array II (2 solutions)

    Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates":What if duplicate ...

  5. 【LeetCode】080. Remove Duplicates from Sorted Array II

    题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...

  6. 【LeetCode】82. Remove Duplicates from Sorted List II 解题报告(Python&C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/remove-du ...

  7. LeetCode OJ 82. Remove Duplicates from Sorted List II

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

  8. leetcode笔记:Remove Duplicates from Sorted Array II

    一.题目描写叙述 二.解题技巧 这道题和Remove Duplicates from Sorted Array这道题是相似的.仅仅只是这里同意出现反复的数字而已,能够採用二分搜索的变种算法.仅仅只是增 ...

  9. LeetCode OJ 80. Remove Duplicates from Sorted Array II

    题目 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ex ...

随机推荐

  1. 浅谈Retrofit2+Rxjava2

    近几年,Retrofit犹如燎原之火搬席卷了整个Android界.要是不懂Retrofit,简直不好意思出门...由于近几个项目都没用到Retrofit,无奈只能业余时间自己撸一下,写的不好的地方,还 ...

  2. Java运行时,指定程序文件的编码

    在命令行cmd里面运行 java -jar test.jar的时候,发现里面执行的汉字发生乱码.原来指定的是UTF-8. 解决如下: java -Dfile.encoding=UTF-8 -jar - ...

  3. Microsoft.Net 版本

    Date Framework Visual Studio C# CLR 2002.2 1.0 Visual Studio 2002 1.0 1.0 2003.4 1.1 Visual Studio 2 ...

  4. Linux QT 连接 Sqlite数据库

    #include <QApplication> #include <QDebug> #include <QSqlQuery> #include <QSqlDa ...

  5. U3D Input类之键位输入GetKey

    Input类中包含许多属性和方法,下面介绍一下和键盘输入有关的内容 一.有关接收键盘信息的属性 属性名 类型 属性类型 含义 anyKey bool get 当前是否按住任意键或鼠标按钮 anyKey ...

  6. js实现四叉树算法

    最近在看canvas动画方面教程,里面提到了采用四叉树检测碰撞.之前也看到过四叉树这个名词,但是一直不是很懂.于是就又找了一些四叉树方面的资料看了看,做个笔记,就算日后忘了,也可以回来看看. Quad ...

  7. 亲身实践 yui-compressor压缩js和css

    最近很懒散,个人感情.家庭原因,没有动力去学东西,老是发誓要搞好前端工程化,老中断,唉!没有魄力! 最近老觉得这前端工程化有什么好的,东西那么多,还得学!直到前几天产品提了个优化,说搜索结果页跳商品详 ...

  8. springboot自定义静态文件目录,解决jar打包后修改页面等静态文件的问题

    1.问题 springboot开发时候,一般将文件放在resources目录,但是发布后想修订文件或是开发时候修改了文件内容一般需重新打包或者重启动才能达到效果: 2.原因 将资源文件打包入jar包, ...

  9. PetaPoco源代码学习--1.使用的Attribute介绍

    新版本的PetaPoco使用特性进行注解的形式来代替的老版本的映射类的形式.新版本中使用的特性主要包括以下几种: 名称   用途 TableNameAttribute Class 指定POCO实体类对 ...

  10. [日常] Go语言圣经-可变参数习题

    1.参数数量可变的函数称为为可变参数函数,例子就是fmt.Printf和类似函数2.参数列表的最后一个参数类型之前加上省略符号“...”3.虽然在可变参数函数内部,...int 型参数的行为看起来很像 ...