【Leetcode】【Easy】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) {
if (!head)
return head; ListNode *p = head; while(p->next) {
if (p->val == p->next->val) {
p->next = p->next->next;
} else {
p = p->next;
}
} return head;
}
};
附录:
C++链表,申请和消除内存
【Leetcode】【Easy】Remove Duplicates from Sorted List的更多相关文章
- LeetCode Linked List Easy 83. Remove Duplicates from Sorted List
Description Given a sorted linked list, delete all duplicates such that each element appear only onc ...
- C# 写 LeetCode easy #26 Remove Duplicates from Sorted Array
26.Remove Duplicates from Sorted Array Given a sorted array nums, remove the duplicates in-place suc ...
- LeetCode Array Easy 26.Remove Duplicates from Sorted Array 解答及疑惑
Description Given a sorted array nums, remove the duplicates in-place such that each element appear ...
- leetcode修炼之路——83. Remove Duplicates from Sorted List
哈哈,我又来了.昨天发现题目太简单就没有放上来,今天来了一道有序链表的题.题目如下: Given a sorted linked list, delete all duplicates such th ...
- LeetCode--LinkedList--83.Remove Duplicates from Sorted List(Easy)
题目地址https://leetcode.com/problems/remove-duplicates-from-sorted-list/ 83. Remove Duplicates from Sor ...
- 83. Remove Duplicates from Sorted List【easy】
83. Remove Duplicates from Sorted List[easy] Given a sorted linked list, delete all duplicates such ...
- 【一天一道LeetCode】#83. Remove Duplicates from Sorted List
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- 【一天一道LeetCode】#80. Remove Duplicates from Sorted Array II
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Follow ...
- 26. Remove Duplicates from Sorted Array【easy】
26. Remove Duplicates from Sorted Array[easy] Given a sorted array, remove the duplicates in place s ...
- 【LeetCode】82. Remove Duplicates from Sorted List II 解题报告(Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/remove-du ...
随机推荐
- 【算法笔记】B1054 求平均值
atof(str)字符串转换浮点数 #include<bits/stdc++.h> using namespace std; bool isLegal(char *s){ ; ]=='-' ...
- 江西理工大学南昌校区排名赛 F: 单身狗的骑马游戏
题目描述 萌樱花是一只单身狗. 萌樱花今天在学姐那里做了一道题: 假设赛马场上有n只马儿,第i只马儿的起点在第i米的位置,这些马儿都会朝着同一个方向奔跑. 每只马儿的速度都不一样,而且大家都不知道这些 ...
- UVA - 11388 唯一分解定理
题意:给出G和L,求最小的a使得gcd(a,b)=G,lcm(a,b)=L 显然a>=G,所以a取G,b要满足质因子质数为L的同次数,b取L //此处应有代码
- [转] Java8 日期/时间(Date Time)API指南
[From] http://www.importnew.com/14140.html Java 8日期/时间( Date/Time)API是开发人员最受追捧的变化之一,Java从一开始就没有对日期时间 ...
- JS调用百度地图。
必要条件:先注册百度开发者账号,然后申请调用地图的密钥(AK). 测试demo: 说明:百度开发平台上有很多demo,如下图:
- mysql PXC集群方案总结
同时写集群内的所有机器 写性能依赖最慢的那个机器 读性能提高X倍
- matplotlib中绘图配色
Python中绘图配色(参照博文: Python-画图(散点图scatter.保存savefig)及颜色大全) # 可以直接使用配色编码 c=["#A52A2A" if tag = ...
- es6 vs commonjs
'use strict' export function showMe() { alert("es6"); }; class logging { constructor() { a ...
- 抽象工厂方法模式(Abstract Factory Pattern)
Provide an interface for creating families of related or dependent objects without specifying their ...
- module.exports和 exports 方法暴露
在Node.js包管理时需要把方法暴露给外部文件 文件:Hello.js Hello方法是模仿面向对象类的写法 function Hello() { var name; this.setName ...