[leetcode.com]算法题目 - 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.
/**
* 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) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
ListNode *p;
p = head;
if(!p) return head; while(p->next){
if(p->next->val == p->val){
ListNode *q;
q=p->next;
p->next = q->next;
delete q;
}
else{
p = p->next; }
} return head;
}
};
思路:考察链表的基本操作,只要注意细节就没问题。
[leetcode.com]算法题目 - Remove Duplicates from Sorted List的更多相关文章
- [算法题] Remove Duplicates from Sorted Array ii
题目内容 本题来源LeetCode Follow up for "Remove Duplicates": What if duplicates are allowed at mos ...
- 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 ...
- <LeetCode OJ> 83. Remove Duplicates from Sorted List
83. Remove Duplicates from Sorted List Total Accepted: 94387 Total Submissions: 264227 Difficulty: E ...
- leetCode练题——26. Remove Duplicates from Sorted Array
1.题目 26. Remove Duplicates from Sorted Array--Easy Given a sorted array nums, remove the duplicates ...
- LeetCode(28)-Remove Duplicates from Sorted Array
题目: Given a sorted array, remove the duplicates in place such that each element appear only once and ...
- LeetCode(80)Remove Duplicates from Sorted Array II
题目 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ex ...
- LeetCode算法题-Remove Duplicates from Sorted List
这是悦乐书的第160次更新,第162篇原创 01 前情回顾 昨晚的爬楼梯算法题,有位朋友提了个思路,使用动态规划算法.介于篇幅问题,这里不细说动态规划算法,以后会在数据机构和算法的理论知识里细说. 昨 ...
- 【算法】LeetCode算法题-Remove Duplicates from Sorted Array
这是悦乐书的第149次更新,第151篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第8题(顺位题号是26).给定一个已经排序(由小到大)的整数数组(元素可以重复),计算其 ...
- [算法题] Remove Duplicates from Sorted Array
题目内容 本题来源于LeetCode Given a sorted array, remove the duplicates in place such that each element appea ...
随机推荐
- mybatis3.2初学感悟
新手,学了mybatis框架一周,写点感悟下来. mybatis,是操作数据库,持久层的一个框架,它是对JDBC的封装.看到了这个框架,我突然感受到封装与抽象的力量.也明白了些为什么要分层的原因. 记 ...
- 2017/2/8 hibernate + oracle 实现id的自增 同时 hibernate项目跑起来 会自己增加字段的原因 oracle触发器的使用
hibernate + oracle 实现id的自增 1.在oracle中先创建一个序列 : 序列语法 如下 create sequence (序列名称)seq_student_id minva ...
- js网页上画图
保存 1.d3.js (http://www.d3.org/)使用svg技术,展示大数据量,动态效果很好,但是API暴露的不好,得靠自己摸索. 2.http://raphaeljs.com/refe ...
- PHP获取手机号
/** * 类名: mobile * 描述: 手机信息类 * 其他: 偶然 编写 */ class mobile{ /** * 函数名称: getPhoneNumber * 函数功能: 取手机号 * ...
- Spring-WebSocket
WebSocket Sockjs Stoup (消息订阅发布) 添加依赖 <!-- 添加依赖 --> <dependencies> <dependency> < ...
- Oracle常用命令-用户、表空间、赋权限、导入导出
1.1 删除表空间 drop tablespace QBKJ including contents and datafiles; 1.2 删除用户 drop user admin cascad ...
- mysql 切换数据库方案
业务场景 在SAAS模式下,不同的租户需要切换数据库,我们可以使用动态数据源,动态数据源有个问题,就是需要对每一个数据库创建一个连接池,在初始化的时候初始化这些连接池, 如果多台应用服务器的情况,每一 ...
- 证明2x2正交矩阵专置后还是正交矩阵
[ x1 x2 y1 y2] x1^2+y1^2=1 x2^2 + y2^2=1 x1*x2 + y1*y2=0 如果专置后还是 x1^2 + x2^2=1 y1^2 +y2^2=1 x1* ...
- 第31章:MongoDB-索引--复合索引
①复合索引 对多个字段创建索引被称为复合索引或者组合索引 ②创建组合索引 创建组合索引(以后台模式创建) db.user.ensureIndex({"username": 1, & ...
- Typecho 二次开发文档链接
快速入门模板入门 模板制作快速入门推荐目录结构 Typecho模板的推荐页面构成模板文件说明 Typecho主题制作文件结构 页面制作制作functions文件: Typecho的functions. ...