3月3日(4) Remove Duplicates from Sorted List
原题 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的更多相关文章
- 【LeetCode】82. Remove Duplicates from Sorted List II 解题报告(Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/remove-du ...
- [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 II 有序数组中去除重复项之二
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- [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-83 Remove Duplicates from Sorted List
#83. Remove Duplicates from Sorted List Given a sorted linked list, delete all duplicates such that ...
- Remove Duplicates from Sorted List II
Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...
- Remove Duplicates From Sorted Array
Remove Duplicates from Sorted Array LeetCode OJ Given a sorted array, remove the duplicates in place ...
- 【leetcode】Remove Duplicates from Sorted Array II
Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates":What if duplicate ...
随机推荐
- 使用 Team Foundation 版本控制命令
使用 Team Foundation 版本控制命令 Visual Studio 2013 其他版本 Visual Studio 2010 Visual Studio 2008 Visual Stu ...
- 0c-35-自动释放池使用注意
.autorelease使用注意 )并不是放到自动释放池中,都会自动加入到自动释放池 1.1) 因为没有调用autorelease方法,所以对象没有加入到自动释放池. int main(){ @aut ...
- Robot Framework简介
概述 Robot Framework是一个通用的关键字驱动自动化测试框架.测试用例以HTML,纯文本或TSV(制表符分隔的一系列值)文件存储. 通过测试库中实现的关键字驱动被测软件.Robot Fra ...
- 深入理解Redis中的主键失效及其实现机制
参考:http://blog.sina.com.cn/s/articlelist_1221155353_0_1.html 作为一种定期清理无效数据的重要机制,主键失效存在于大多数缓存系统中,Reids ...
- mysql分表研究
分表是分散数据库压力的好方法. 分表,最直白的意思,就是将一个表结构分为多个表,然后,可以再同一个库里,也可以放到不同的库. 当然,首先要知道什么情况下,才需要分表.个人觉得单表记录条数达到百万到千万 ...
- 如何通过apt-get获得安装包的源码
有时候我们需要获得某个可执行程序的源码,而不仅仅是一个可执行程序,比如我们想获取tree这个工具的源码,这时候就可以采用下面的命令: sudo apt-get source tree pengdl@d ...
- linux modprobe命令参数及用法详解--linux加载模块命令
转:http://www.linuxso.com/command/modprobe.html modprobe(module probe) 功能说明:自动处理可载入模块. 语 法:modprobe [ ...
- Linux数据归档和解压缩tar,cpio,gzip,bzip,lzma,zip命令使用
转载:http://www.1987.name/659.html 数据压缩归档和备份是系统管理的日常工作,定期备份不可小视,归档和压缩对于系统管理员或是普通用户来说都经常用到的操作,有很多中压缩格式, ...
- c#实现无标题栏窗口的拖动
当把窗体的FormBorderStyle属性设为None后会导致边框没了,结果窗体无法用鼠标拖动.最大.最下化和关闭…… 下面解决窗体可拖动问题:1.首先导入命名空间: using System.Ru ...
- Java基础知识强化之IO流笔记72:NIO之 NIO核心组件(NIO使用代码示例)
1.Java NIO 由以下几个核心部分组成: Channels(通道) Buffers(缓冲区) Selectors(选择器) 虽然Java NIO 中除此之外还有很多类和组件,Channel,Bu ...