原题 Remove Duplicates from Sorted List

有序单链表去重,delete 只能对指针起作用。

/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *deleteDuplicates(ListNode *head) { if (head == NULL) return NULL; ListNode *pp = head;
ListNode *p = head->next; while (p != NULL)
{
if (p->val == pp->val)
{
pp->next = p->next;
delete p;
p = pp->next;
continue;
}
pp = p;
p = p->next;
};
return head;
}
};

3月3日(4) Remove Duplicates from Sorted List的更多相关文章

  1. 【LeetCode】82. Remove Duplicates from Sorted List II 解题报告(Python&C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/remove-du ...

  2. [LeetCode] Remove Duplicates from Sorted List 移除有序链表中的重复项

    Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...

  3. [LeetCode] Remove Duplicates from Sorted List II 移除有序链表中的重复项之二

    Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...

  4. [LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二

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

  5. [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项

    Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...

  6. Leetcode-83 Remove Duplicates from Sorted List

    #83. Remove Duplicates from Sorted List Given a sorted linked list, delete all duplicates such that ...

  7. Remove Duplicates from Sorted List II

    Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...

  8. Remove Duplicates From Sorted Array

    Remove Duplicates from Sorted Array LeetCode OJ Given a sorted array, remove the duplicates in place ...

  9. 【leetcode】Remove Duplicates from Sorted Array II

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

随机推荐

  1. 在Shell中使用函数文件

    需要编写一个较庞大的脚本时,可能会涉及许多函数.变量.这是通常建议将众多的函数.变量放入一个单独的脚本内.这样做的好处很明显,不用担心某个函数.变量是否已经被定义和使用,也不用频繁地定义.清除函数和变 ...

  2. LOG4J.PROPERTIES配置详解(转载)

    Log4J的配置文件(Configuration File)就是用来设置记录器的级别.存放器和布局的,它可接key=value格式的设置或xml格式的设置信息.通过配置,可以创建出Log4J的运行环境 ...

  3. IOS 按比例裁剪图片

    拍照或者从图片库中获取图片 操作过程中容易闪退,也总会有内存压力警告,第一步,首先可以考虑裁剪图片,实际上可能不需要那么大的.其次可以考虑把耗时的比如存储过程放进线程. 这里封装裁剪图片的类方法. / ...

  4. IOS plist轻量级操作

    plist,全名PropertyList,即属性列表文件,它是一种用来存储串行化后的对象的文件.这种文件,在ios开发过程中经常被用到.这种属性列表文件的扩展名为.plist,因此通常被叫做plist ...

  5. Html方式导出word 页头和页脚设置

    <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:o ...

  6. XAMPP搭建的几个注意事项

    使用xampp搭建php本地开发环境是一个不错的解决方案. 我搭建时选择的是不使用安装包安装,再启动过程中出现了些问题. xampp下载地址:http://www.apachefriends.org/ ...

  7. 【Shell脚本学习18】Shell for循环

    与其他编程语言类似,Shell支持for循环. for循环一般格式为: for 变量 in 列表 do command1 command2 ... commandN done 列表是一组值(数字.字符 ...

  8. CALayer 简单操作和实际应用

    1.CALayer //每一个UIView,都存在一个CALayer.(主层) //CALayer的功能 描边,圆角,阴影... //CALayer 属于QuartzCore绘图框架 //明明有UIC ...

  9. 存储过程 <3> 和函数的区别

    二.函数和存储过程的优点: 1.共同使用的代码可以只需要被编写一次,而被需要该代码的任何应用程序调用(.net,c++,java,也可以使DLL库). 2.这种几种编写.几种维护更新.大家共享的方法, ...

  10. 【MongoDB】MongoDB服务器搭建(Unix/Linux)

    1.安装MongboDB安装包(开源免费的哟) 在Mac 下 brew install mongoDB 就可以啦 安装要等一会儿,大概200M 2. cd到MongboDB文件夹 - 如果是用home ...