[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 ...
随机推荐
- Mysql主从数据同步cheksum问题
做主从同步时出现问题,show slave status显示错误: Last_IO_Error: Got fatal error from master when reading data from ...
- ZendFramework-2.4 源代码 - 路由(类图)
<?php return array( // console 模式 'console'=>array( 'router' => array( //.... ), ), // http ...
- 第1章 VMware中安装CentOS7
目录 1.1 下载CentOS7安装包 1.2 VMware中新建虚拟机 1.3 安装操作系统 本章讲解在VMware中安装CentOS虚拟机的步骤.使用的VMware Workstation版本为1 ...
- [BZOJ1588]营业额统计(Splay)
Description 题意:给定 n个数,每给定一个数,在之前的数里找一个与当前数相差最小的数,求相差之和(第一个数为它本身) 如:5 1 2 5 4 6 Ans=5+|1-5|+|2-1|+|5- ...
- complex类的定义、实现
复数类complex的定义.实现(求模.复数加法) #include <iostream> #include <cmath> using namespace std; clas ...
- django 自定义过滤器中的坑.
今天在创建自定义过滤器的时候,设置已正常.但是在运行后报: 'filter' is not a valid tag library: Template library filter not found ...
- Collection record
复习大集合: 1.函数的参数:位置参数,关键字参数,动态参数 2.命名空间:内置命名空间,全局命名空间,局部命名空间 3.闭包函数:函数引用未定义的函数外非全局的变量叫做闭包,该函数称为闭包函数 4. ...
- loj2090 「ZJOI2016」旅行者
分治+最短路,很套路的 #include <algorithm> #include <iostream> #include <cstring> #include & ...
- IOS开发---菜鸟学习之路--(十五)-如何实现拍照功能
本章将来讲解下如何实现拍照的功能 我们需要的实现的效果是 好了 直接开始内容吧 首先我们需要新建一个ViewController 就叫AddPictureViewController 然后选 ...
- 新博客 http://kunyashaw.com/
感谢博客园. 请关注我的新博客: http://kunyashaw.com/