[LeetCode] Remove Duplicates from Sorted List 链表
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2
, return 1->2
.
Given 1->1->2->3->3
, return 1->2->3
.
class Solution {
public:
ListNode *deleteDuplicates(ListNode *head) {
if(head==NULL) return NULL;
ListNode *lp = head,*rp = head;
while(rp!=NULL){
while(rp!=NULL&&rp->val==lp->val) rp=rp->next;
lp->next = rp;
lp = rp;
}
return head;
}
};
[LeetCode] Remove Duplicates from Sorted List 链表的更多相关文章
- LeetCode:Remove Duplicates from Sorted List I II
LeetCode:Remove Duplicates from Sorted List Given a sorted linked list, delete all duplicates such t ...
- LeetCode:Remove Duplicates from Sorted Array I II
LeetCode:Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place su ...
- [LeetCode] Remove Duplicates from Sorted List 移除有序链表中的重复项
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- [LeetCode] Remove Duplicates from Sorted List II 移除有序链表中的重复项之二
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- [LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- [Leetcode] Remove Duplicates From Sorted Array II (C++)
题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...
- Leetcode: Remove Duplicates from Sorted List II 解题报告
Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...
- [LeetCode]Remove Duplicates from Sorted Array题解
Remove Duplicates from Sorted Array: Given a sorted array, remove the duplicates in place such that ...
随机推荐
- 【File】文件操作(初识文件操作一)
一,初识文件流 看到标题就知道接下来的所有操作对象都是面对文件进行的.那么问题来了.在java中目录是不是也属于文件呢?答案是yes.既然目录也属于文件,那么对于目录跟文件的区分就显现出来了.在接下来 ...
- (JAVA指针),对象引用问题
引出指针 从表面上看JAVA是没有指针的,或者是说,弱化了指针.但是指针在JAVA中还是真真切切存在的.在Java中我们称之为引用. String a;//引用为空 String a = new S ...
- MVC中Spring.net 对基类控制器无效 过滤器控制器无效
比如现在我又一个BaseController作为基类控制器,用于过滤权限.登录判断等作用,其它控制由原本的继承Controller,改为继承BaseController.然后BaseControlle ...
- HDU 3333 Turing Tree 莫队算法
题意: 给出一个序列和若干次询问,每次询问一个子序列去重后的所有元素之和. 分析: 先将序列离散化,然后离线处理所有询问. 用莫队算法维护每个数出现的次数,就可以一边移动区间一边维护不同元素之和. # ...
- 驱动模块 .ko
模块: 模块机制,作用搞高LINUX操作系统的扩充性. 1. 模块概念: 1.动态可加载内核模块LKM 2.内核空间运行 3.是不是一执行文件,是一个没有经过链接,不能独立运行的一个目标文件(.c-& ...
- Windows下MySQL8.0.11.0安装教程
1.mysql下载地址:https://dev.mysql.com/downloads/installer/ 2.下载安装MySQL 8.0.11.0 https://cdn.mysql.com//D ...
- [oldboy-django][2深入django]老师管理 -- form表单如何生成多选框标签,多选框的默认值显示,以及多选框数据插入到数据库,多选框数据更改到数据库
1 form表单如何生成多选框(包含了多选框可选择内容) - Form设置班级输入框为 select多选 - 多选 class TeacherForm(Form): name = fields.Cha ...
- (转载)CentOS 6.5使用aliyun镜像来源
(原地址:http://www.linuxidc.com/Linux/2014-09/106675.htm) 当我们把CentOS 6.5安装好以后,可以使用这个脚本来使用国内的阿里云镜像源 #!/b ...
- ActionContext和ServletActionContext小结
1. ActionContext 在Struts2开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话(Session)的一些信息, ...
- 使用CoreLocation进行定位(Swift版)
在应用开发中,很多情况需要我们获取到当前的位置和高度信息,方便搜索周边,查看周边相同应用等,一切与定位有关的都得使用CoreLocation库,而且,系统是不允许第三发定位的,当然可以使用第三方对其封 ...