[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 ...
随机推荐
- JZOJ 4732. 【NOIP2016提高A组模拟8.23】函数
4732. [NOIP2016提高A组模拟8.23]函数 (Standard IO) Time Limits: 1500 ms Memory Limits: 262144 KB Detailed ...
- Liunx环境--Node部署记录
1.看看环境里有没有装Node which node 2.找个目录安装 (1)/usr/local/node/download 执行下载 wget https://nodejs.org/dist/v8 ...
- Java中创建(实例化)对象的五种方式
Java中创建(实例化)对象的五种方式1.用new语句创建对象,这是最常见的创建对象的方法. 2.通过工厂方法返回对象,如:String str = String.valueOf(23); 3.运用反 ...
- 笔记-python-standard library-17.2 multiprocessing
笔记-python-standard library-17.2 multiprocessing 1. multiprocessing source code:Lib/multiprocess ...
- kettle - Linux下定时执行kettle作业
Linux下实现kettle 自动同步数据 1.安装jdk tar -zxvf jdk-7u25-linux-x64.tar.gz -C /usr/share 2.配置java环境 vim /etc/ ...
- Android通过AIDL和反射调用系统拨打电话和挂断电话
首先在项目中添加ITelephony.aidl文件,我的如下: /* * Copyright (C) 2007 The Android Open Source Project * * Licensed ...
- #2 create and populate a database && realistic and practical applications (PART 2)
Extends from the last chapter , This chapter takes a look at some real-world problems that can occur ...
- 图学java基础篇之集合工具
两个工具类 java.utils下又两个集合相关_(准确来说其中一个是数组的)_的工具类:Arrays和Collections,其中提供了很多针对集合的操作,其中涵盖了一下几个方面: 拷贝.填充.反转 ...
- jni 调用
Event 0 on null Unexpected event 0 on /storage/emulated/0/Books/null
- XmlSerializer 短信备份
package com.itheima.mobileguard.utils; import java.io.File; import java.io.FileNotFoundException; im ...