链表-remove duplicates from sorted list

struct ListNode* deleteDuplicates(struct ListNode* head) {
struct ListNode *p=head;
if(!head)
return head;
while(p&&p->next)
{
if(p->val==p->next->val)
p->next=p->next->next;
else
p=p->next;
}
return head;
}
要注意考虑1->1->1这种情况,第一个1要和后面比较多次。
链表-remove duplicates from sorted list的更多相关文章
- [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 203. Remove Linked List Elements 、83. Remove Duplicates from Sorted List 、82. Remove Duplicates from Sorted List II(剑指offer57 删除链表中重复的结点)
203题是在链表中删除一个固定的值,83题是在链表中删除重复的数值,但要保留一个:82也是删除重复的数值,但重复的都删除,不保留. 比如[1.2.2.3],83题要求的结果是[1.2.3],82题要求 ...
- [LeetCode] 83. Remove Duplicates from Sorted List 移除有序链表中的重复项
Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1 ...
- [LeetCode] 82. Remove Duplicates from Sorted List II 移除有序链表中的重复项之二
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- [LeetCode] 82. Remove Duplicates from Sorted List II 移除有序链表中的重复项 II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- LeetCode 82. 删除排序链表中的重复元素 II(Remove Duplicates from Sorted List II)
82. 删除排序链表中的重复元素 II 82. Remove Duplicates from Sorted List II 题目描述 给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中没有 ...
- LeetCode之“链表”:Remove Duplicates from Sorted List && Remove Duplicates from Sorted List II
1. Remove Duplicates from Sorted List 题目链接 题目要求: Given a sorted linked list, delete all duplicates s ...
- Remove Duplicates from Sorted List ,除去链表中相邻的重复元素
Remove Duplicates from Sorted List : Given a sorted linked list, delete all duplicates such that eac ...
随机推荐
- Jquery 解决 H5 placeholder元素问题
<style type="text/css"> .placeholder{ color: #cacaca; } </style> <script ty ...
- cocos2d-x中常见的场景切换
本文转载自:http://www.cnblogs.com/linux-ios/archive/2013/04/09/3010779.html bool HelloWorld::init() { /// ...
- EEPROM和flash的区别
存储器分为两大类:ram和rom.ram就不讲了,今天主要讨论rom. rom最初不能编程,出厂什么内容就永远什么内容,不灵活.后来出现了prom,可以自己写入一次,要是写错了,只能换一片,自认倒霉. ...
- MAC 下使用ipv6、ipv4观看电视、网络电视
换了mac book,ipv6电视却看不了了,为了看电视,只要自己动手了. 关于ipv6是啥和哪里有ipv6这里就不说了,找度娘吧. 我们观看IPv6视频直播信号有两种,一种是mms协议,另外一种 ...
- C++实现线程池 .
C++实现线程池. 欢迎转载,转载请注明原出处:http://blog.csdn.net/ithzhang/article/details/9020283 代码地址:https://github.co ...
- Android各层推荐开发书籍及参考资料
Android各层推荐开发书籍及参考资料 转自:http://blog.csdn.net/fancylovejava/article/details/8657058 Android系统按照架构来说一共 ...
- mssql中得到当天数据的语句
一条例子: 关键语句:
- WISE安装程序增加注册控制
我做安装程序,一直用的WISE 9.最近为一个用户提供安装程序时,公司要求对安装程序增加控制,避免用户到处安装,增加公司服务的压力.因此,我在WISE制作的安装程序中增加了注册码校验控制,不能给出正确 ...
- java 为pdf添加水印图片
首先需要引入两个Jar包分别是:iTextAsian.jar .itext-2.1.7.jar 可以去 http://download.csdn.net/detail/work201003/922 ...
- Haffman编码(haffman树)
Haffman编码 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 哈弗曼编码大家一定很熟悉吧(不熟悉也没关系,自己查去...).现在给你一串字符以及它们所对应的权值 ...