【LeetCode】83 - 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.
Solution:
/**
* 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 head;
ListNode* temp = head,*cur = head->next;
while(cur)
{
if(cur->val != temp->val)
{
temp->next = cur;
temp = temp->next;
}
cur = cur->next;
}
temp->next = NULL;
return head;
}
};
【LeetCode】83 - Remove Duplicates from Sorted List的更多相关文章
- 【LeetCode】83 - 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 解题报告(C++&Java&Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 判断相邻节点是否相等 使用set 使用列表 递归 日 ...
- 【一天一道LeetCode】#83. Remove Duplicates from Sorted List
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- 【LeetCode】82. Remove Duplicates from Sorted List II 解题报告(Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/remove-du ...
- 【LeetCode】80. Remove Duplicates from Sorted Array II (2 solutions)
Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates":What if duplicate ...
- 【LeetCode】080. Remove Duplicates from Sorted Array II
题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...
- 【leetcode】 26. Remove Duplicates from Sorted Array
@requires_authorization @author johnsondu @create_time 2015.7.22 18:58 @url [remove dublicates from ...
- 【LeetCode】26. Remove Duplicates from Sorted Array 解题报告(Python&C++&Java)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 日期 [LeetCode] https:// ...
- 【LeetCode】80. Remove Duplicates from Sorted Array II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
随机推荐
- CrazePony飞行器--通信部分介绍【转】
转自:http://www.crazepony.com/wiki/comm-protocol.html 作者:nieyong 通信协议指的是遥控端和主控之间交互数据的封装,是一种自行约定的数据封装格式 ...
- leetcode:Isomorphic Strings
Isomorphic Strings Given two strings s and t, determine if they are isomorphic. Two strings are isom ...
- 安全删除mysql binlog日志
命令行下执行 show binary logs; purge binary logs to 'mysql-bin.000070';
- windows主机无法访问服务器
在CentOS下安装配置hadoop的时候,总显示因为网络端口而导致主机无法访问服务器,遂打算先关闭一下防火墙. 偶然看到防火墙的配置操作说明,感觉不错.执行”setup”命令启动文字模式配置实用程序 ...
- 30条MySQL优化总结
1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...
- 实现图片大小的自动控制( 图片大小控制CSS代码)
图片大小控制CSS代码 将以下代码放到你的样式表文件中即可实现图片大小的自动控制. /*图片大小控制CSS By Tekin */img,a img{border:0;margin:0;padding ...
- mysql 存储过程 事务; mysql的事务中包含一个存储过程
在asp.net结合mysql的开发中,我平时用到的事务处理是 使用 TransactionOptions 来进行处理 TransactionOptions transactionOption = ...
- SQL语句方法语法总结(二)
1.给表插入数据. (1)INSERT INTO TBL_NAME VALUES (VALUE_1,VALUE_2,...) (2)INSERT INTO TBL_NAME (COL_1,COL_2, ...
- Linux ARM kernel Makefile and Kconfig
kernel build:顶层Makefile:-->1. include build/main.mk -->2. include build/kernel.mk k ...
- vijos 1379 字符串的展开
23333333333333333 #include<iostream> #include<cstdio> #include<cstring> #include&l ...