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 ...
随机推荐
- asp.net(C#)之NPOI"操作Excel
1.首先到网上下载"NPOI.DLL".引用. 2.新建一个操作类"ExcelHelper.cs": using System.Collections.Gene ...
- ZOJ 3529 A Game Between Alice and Bob(博弈论-sg函数)
ZOJ 3529 - A Game Between Alice and Bob Time Limit:5000MS Memory Limit:262144KB 64bit IO For ...
- 二进制搜索方法C++通用执行
算法很easy.直接附着到代码它 #include <iostream> using namespace std; template<typename T> int binar ...
- (Google面试题)有四个线程1、2、3、4。线程1的功能就是输出1,线程2的功能就是输出2,以此类推.........现在有四个文件ABCD。初始都为空。
现要让四个文件呈如下格式: A:1 2 3 4 1 2.... B:2 3 4 1 2 3.... C:3 4 1 2 3 4.... D:4 1 2 3 4 1.... 请设计程序. 下面举例A,对 ...
- 第四题(迅雷笔试题):编写一个程序,开启3个线程,这3个线程的ID分别为A、B、C,每个线程将自己的ID在屏幕上打印10遍,要求输出结果必须按ABC的顺序显示;如:ABCABC….依次递推。
#include <iostream> #include <stdlib.h> #include <pthread.h> using namespace std; ...
- VSC调试.NET Core 应用程序
VS Code 从零开始开发并调试.NET Core 应用程序 使用VS Code 从零开始开发并调试.NET Core 应用程序,C#调试. 上一篇 使用VS Code开发 调试.NET Core ...
- Eclipse乱码怎么办
Eclipse里设置编码有三个层次:全局.工程.文件. 文件的编码会覆盖工程的编码,工程的编码会覆盖全局的编码. 我猜测:虽然你的工程编码更改为GBK,但只对新建文件有效. 如果工程中旧有的文件是UT ...
- hdu2063+hdu1083(最大匹配数)
传送门:hdu2063过山车 #include <cstdio> #include <cstring> #include <string> #include < ...
- Python基础 - 关键字
前言 与C一样,python也有自己的关键字,关键字有特殊的意义,不能作为普通的变量名类名等用途 关键字列表 以python2.7.5为例,有如下关键字: and del from not while ...
- 为何要fork()两次来避免产生僵尸进程?
为何要fork()两次来避免产生僵尸进程? 当我们只fork()一次后,存在父进程和子进程.这时有两种方法来避免产生僵尸进程: 父进程调用waitpid()等函数来接收子进程退出状态. 父进程先结 ...