删除重复节点列表中的。假设所有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的更多相关文章

  1. LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++>

    LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++> 给出排序好的一维数组,如果一个元素重复出现的次数 ...

  2. 【leetcode】Remove Duplicates from Sorted Array II

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

  3. [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% ...

  4. [leetcode] 80. Remove Duplicates from Sorted Array II (Medium)

    排序数组去重题,保留重复两个次数以内的元素,不申请新的空间. 解法一: 因为已经排好序,所以出现重复的话只能是连续着,所以利用个变量存储出现次数,借此判断. Runtime: 20 ms, faste ...

  5. [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 ...

  6. [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 ...

  7. [LeetCode] 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] 80. Remove Duplicates from Sorted Array II 有序数组中去除重复项之二

    Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twic ...

  9. LeetCode OJ Remove Duplicates from Sorted Array II

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

随机推荐

  1. 自学PHP 环境搭建

    自学PHP之环境搭建 一..首先 安装 phpStudy2013.exe 程序集成包  安装完可能端口被占用 需要手动设置 然后打开http://localhost:8080/phpMyAdmin/ ...

  2. hdu2159 Fate 二维背包

    #include <cstring> #include <string> #include <cstdio> #include <cmath> #inc ...

  3. Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException

    1.错误描写叙述 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -he ...

  4. VC生成的DLL给QT的EXE调用时lib路径问题小结

    VC生成的DLL给QT调用,有两种方式,一种是隐式调用调用(使用.lib文件方式): ① 在*.pro工程文件中添加VC生成的lib文件路径时,或者使用一个绝对路径,如: LIBS += " ...

  5. [计算机基础]HTTP协议学习笔记

    HTTP:Hypertext transfer protocol超文本传输协议是一种详细规定了浏览器和Internet之间互相通信的规则 HTTP允许传输任意类型的数据对象,由Content-Type ...

  6. 14.3.4 Phantom Rows 幻影行

    14.3.4 Phantom Rows 幻影行 所谓的幻读为发生在一个事务 当相同的查询产生不同的结果集在不同的时间. 比如,如果一个SELECT被执行2次, 但是第2次返回的记录不是第一次返回的记录 ...

  7. junit4同一时候測试多个測试类

    两个分别须要的測试类 TestSuit001 package com.test.junit; import org.junit.Test; public class TestSuit001 { @Te ...

  8. linux signal之初学篇

    前言 本博文只总结signal的应用,对signal的kernel实现暂不讨论. 1. linux signal是什么? signal是linux提供的用于进程间通信的一种IPC机制. 2. 如何发送 ...

  9. 【UVA】10012 - How Big Is It?(暴力)

    使用DFS枚举所有的安排.每次加入后,当一个圆.他的立场是最大的,并已加入了圆环中的所有切线位置前面. 14383635 10012 option=com_onlinejudge&Itemid ...

  10. 模拟spring框架注入实现原理

    这个我是参见了别人的一些东西,不是原创! 定义一些抽象的方法: package com.huxin.springinject.dao; public interface Person { public ...