leetcode先刷_Remove Duplicates from Sorted List II
删除重复节点列表中的。假设所有val如果仅仅是为了保持一个非常easy。应承担重复val节点被删除话。要保持pre节点。每当你想保存这pre问题节点,应该head节点可以被取出,好了,没问题边境控制。
class Solution {
public:
ListNode *deleteDuplicates(ListNode *head) {
if(head == NULL || head->next == NULL)
return head;
ListNode *pre = NULL, *start = head, *end;
while(start){
while(start&&start->next&&start->val != start->next->val){
pre = start;
start = start->next;
}
end = start;
while(end&&end->next&&end->val == end->next->val)
end = end->next;
if(end!=start&&end){
if(pre)
pre->next = end->next;
else{
head = end->next;
}
}else{
break;
}
start = end->next;
}
return head;
}
};
版权声明:本文博客原创文章,博客,未经同意,不得转载。
leetcode先刷_Remove Duplicates from Sorted List II的更多相关文章
- LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++>
LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++> 给出排序好的一维数组,如果一个元素重复出现的次数 ...
- 【leetcode】Remove Duplicates from Sorted Array II
Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates":What if duplicate ...
- [LeetCode] 80. Remove Duplicates from Sorted Array II ☆☆☆(从有序数组中删除重复项之二)
https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/discuss/27976/3-6-easy-lines-C% ...
- [leetcode] 80. Remove Duplicates from Sorted Array II (Medium)
排序数组去重题,保留重复两个次数以内的元素,不申请新的空间. 解法一: 因为已经排好序,所以出现重复的话只能是连续着,所以利用个变量存储出现次数,借此判断. Runtime: 20 ms, faste ...
- [LeetCode] 80. Remove Duplicates from Sorted Array II 有序数组中去除重复项 II
Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twic ...
- [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 移除有序链表中的重复项之二
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- [LeetCode] 80. Remove Duplicates from Sorted Array II 有序数组中去除重复项之二
Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twic ...
- LeetCode OJ Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
随机推荐
- WM_PAINT产生原因有2种(用户操作和API)——WM_PAINT和WM_ERASEBKGND产生时的先后顺序不一定(四段讨论)
1. 当WM_PAINT不是由InvalidateRect产生时,即由最大化,最小化等产生时,或者移动产生(移动有时只会产生WM_ERASEBKGND消息)系统先发送WM_ERASEBKGND消息,再 ...
- Mysql免安装版脚本
使用Mysql过程中经常需要使用到免安装版本(绿色版)的Mysql,开始网上搜了一大堆,但还真是不怎么好用. 只好自己琢磨了一番,现在放出来和大家分享下: //安装启动服务 @ECHO OFF if ...
- 此三层非彼三层——MVC&UBD
学习了三年编程了,到如今这个阶段,開始接触架构,開始认识架构,怎样设计一个程序的结构,学名称"架构模式"(architectural pattern).个人经历告诉我这在编程中是一 ...
- jQuery选择
1.基本的选择 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY29tZW9uc3RvbmU=/font/5a6L5L2T/fontsize/400/fil ...
- codeforces.com/contest/325/problem/B
http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...
- 14.3.5.3 How to Minimize and Handle Deadlocks 如何减少和处理死锁
14.3.5.3 How to Minimize and Handle Deadlocks 如何减少和处理死锁 这个章节建立关于死锁的概念信息,它解释如何组织数据库操作来减少死锁和随后的错误处理: D ...
- Python批量删除指定目录下的指定类型的文件
Python作为一种脚本语言.其很适合文件级的各种操作.以下的代码能够批量删除指定目录下的所有特定类型(CSV类型)的文件. import sys, csv , operator import os ...
- 自己动手写处理器之第一阶段(2)——MIPS指令集架构的演变
将陆续上传本人写的新书<自己动手写处理器>(尚未出版),今天是第三篇.我尽量每周四篇 MIPS指令集架构自上世纪80年代出现后.一直在进行着更新换代,从最初的MIPS I到MIPS V,发 ...
- JavaScript 中的事件类型5(读书笔记思维导图)
Web 浏览器中可能发生的事件有很多类型.如前所述,不同的事件类型具有不同的信息,而“ DOM3级事件”规定了以下几类事件. UI(User Interface,用户界面)事件:当用户与页面上的元素交 ...
- 整理自百度知道提问的几道Java编程题
蚂蚁爬杆 问题描述: 有一根27厘米的细木杆,在第3厘米.7厘米.11厘米.17厘米.23厘米这五个位置上各有一只蚂蚁.木杆很细,不能同时通过一只蚂蚁.开始时,蚂蚁的头朝左还是朝右是任意的,它们只会朝 ...