删除重复节点列表中的。假设所有val如果仅仅是为了保持一个非常easy。应承担重复val节点被删除话。要保持pre节点。每当你想保存这pre问题节点,应该head节点可以被取出,好了,没问题边境控制。

  1. class Solution {
  2. public:
  3. ListNode *deleteDuplicates(ListNode *head) {
  4. if(head == NULL || head->next == NULL)
  5. return head;
  6. ListNode *pre = NULL, *start = head, *end;
  7. while(start){
  8. while(start&&start->next&&start->val != start->next->val){
  9. pre = start;
  10. start = start->next;
  11. }
  12. end = start;
  13. while(end&&end->next&&end->val == end->next->val)
  14. end = end->next;
  15. if(end!=start&&end){
  16. if(pre)
  17. pre->next = end->next;
  18. else{
  19. head = end->next;
  20. }
  21. }else{
  22. break;
  23. }
  24. start = end->next;
  25. }
  26. return head;
  27. }
  28. };

版权声明:本文博客原创文章,博客,未经同意,不得转载。

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. C语言函数调用约定

    在C语言中,假设我们有这样的一个函数: int function(int a,int b) 调用时只要用result = function(1,2)这样的方式就可以使用这个函数.但是,当高级语言被编译 ...

  2. 修改Tabhost样式和字体大小和居中显示

    有时候我们的tabhost并不需要贴图,所以这个时候就必须把文字居中显示和设置大小了,代码如下 setContentView(R.layout.home_vzo_tabhost);          ...

  3. delphi 回调函数

    program Project2; {$APPTYPE CONSOLE} uses SysUtils; type //定义一个对象事件方法 TCallbackFunc = function (i: I ...

  4. ThinkPHP 自动创建数据、自动验证、自动完成详细例子介绍(十九)

    原文:ThinkPHP 自动创建数据.自动验证.自动完成详细例子介绍(十九) 1:自动创建数据 //$name=$_POST['name']; //$password=$_POST['password ...

  5. hdu 3221 Brute-force Algorithm(高速幂取模,矩阵高速幂求fib)

    http://acm.hdu.edu.cn/showproblem.php?pid=3221 一晚上搞出来这么一道题..Mark. 给出这么一个程序.问funny函数调用了多少次. 我们定义数组为所求 ...

  6. 怎样处理iOS 5与iOS 6的 low-memory

    移动设备终端的内存极为有限,应用程序必须做好low-memory处理工作,才能避免程序因内存使用过大而崩溃. low-memory 处理思路 通常一个应用程序会包含多个view controllers ...

  7. Android真机网络adb联机调试初探

    新项目是一个基于android4.2设备.刚拿到demo板时就对联机互调感兴趣了.处于以前在S3c2440上对linux的移植使用经验.心里猜测对于android设备应该也这样.所以通过搜索资料整理如 ...

  8. Python多线程2:sched

    sched模块提供了一个类的事件安排. scheduler类定义 class sched.scheduler(timefunc=time.monotonic, delayfunc=time.sleep ...

  9. cocos2dx-3.0(1)------win7 32位android环境搭建

    參照链接http://blog.csdn.net/wonengxing/article/details/23601359 ----我的生活,我的点点滴滴!! 一. Android工具安装 1. 安装J ...

  10. Nginx 进程间通信

    Linux下的IPC非常多,nginx的进程都是有亲缘关系的进程,对于他们的通信我们选择TCP socket进行通信.   TCP socket 用来做进程通信的优点有,   1.socket是文件描 ...