82. Remove Duplicates from Sorted List II (List)
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.
class Solution {
public:
ListNode *deleteDuplicates(ListNode *head) {
if(!head) return head;
ListNode *previous = NULL;
ListNode *current = head;
bool repeat = false;
while(current)
{
while(current->next && current->val == current->next->val)
{
current = current->next;
repeat = true;
}
if(repeat && previous!= NULL)
{
previous->next = current->next;
}
else if(!repeat)
{
if(!previous) head = current;
previous = current;
}
current = current->next;
repeat = false;
}
if(!previous) return previous;
return head;
}
};
82. Remove Duplicates from Sorted List II (List)的更多相关文章
- leetcode 203. Remove Linked List Elements 、83. Remove Duplicates from Sorted List 、82. Remove Duplicates from Sorted List II(剑指offer57 删除链表中重复的结点)
203题是在链表中删除一个固定的值,83题是在链表中删除重复的数值,但要保留一个:82也是删除重复的数值,但重复的都删除,不保留. 比如[1.2.2.3],83题要求的结果是[1.2.3],82题要求 ...
- 82. Remove Duplicates from Sorted List II && i
题目 83. Remove Duplicates from Sorted List Given a sorted linked list, delete all duplicates such tha ...
- 82. Remove Duplicates from Sorted List II【Medium】
82. Remove Duplicates from Sorted List II[Medium] Given a sorted linked list, delete all nodes that ...
- [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 OJ 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 移除有序链表中的重复项 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 解题报告(Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/remove-du ...
- [LeetCode#82]Remove Duplicates from Sorted Array II
Problem: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? F ...
- 82. Remove Duplicates from Sorted List II
题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct ...
- leetcode 82. Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
随机推荐
- ballerina 学习五 使用composer管理ballerina 项目
1. 启动 composer 备注: 因为这个命名和php的一个包管理工具重名了,所以可能需要使用决定路径 比如我的mac系统使用:Library/Ballerina/ballerina-0.970. ...
- Jitsi 开源视频会议远程桌面共享&&文档共享工具
1. 特点 主要功能特点: 支持网络视频会议,使用SFU模式实现视频路由器功能. 支持SIP帐号注册电话呼叫. 支持安卓苹果终端. 支持文档共享功能,即时消息功能. 支持中文界面. 支持会议邀请,密码 ...
- oralce之 10046对Hash Join分析
前两天解决了一个优化SQL的case,SQL语句如下,big_table为150G大小,small_table很小,9000多条记录,不到1M大小,hash_area_size, sort_area_ ...
- vue的路由初识01
今天就做了一个vue-router的实例,(路由跳转,参数的传递[一个参数,多个参数])<!DOCTYPE html> <html> <head> <meta ...
- 如何用TortoiseSVN管理本地文档
1.安装(略) 2.搭建本地SVN版本管理数据库(服务器) (1)在本地磁盘上新建一个目录,例如E:\SVN,用来存储各种需要进行版本管理的文档:接着在该目录下再创建一个新的空目录,例如创建一个E:\ ...
- 论BOM管理的若干重要问题
在制造业信息化建设过程中,BOM管理的意义已经被广泛认同与重视.BOM管理是企业产品数据管理领域要解决的核心问题,对制造企业的信息流和业务流程具有重要影响,可以说企业BOM数据架构已是企业架构的一部分 ...
- wkhtmltopdf Windows下 测试demo 成功
html2pdf 转pdf 中文不换行 然后找到了wkhtmltopdf 支持中文换行 样式也支持 在PHP中生成PDF文件,可以使用 FPDF 和 TCPDF .但是它们只能用于创建简单的表格,当涉 ...
- 一步步实现 Redis 搜索引擎
来源:jasonGeng88 github.com/jasonGeng88/blog/blob/master/201706/redis-search.md 如有好文章投稿,请点击 → 这里了解详情 场 ...
- 解决“在上下文中找不到 owin.Environment 项”
网站发布到虚拟空间后,提示以下错误:在上下文中找不到 owin.Environment 项",百度了好长时间都没有解决.最后在web.config中添加以下配置. <system.we ...
- linux/ubuntu 端口开放
在ubuntu下面开放端口好像主要有两种方法,一种是ubuntu自带的防火墙,一种是iptables,这里我们主要使用iptables.本文的系统版本为ubuntu14.04和ubuntu16.04 ...