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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. leetcode修炼之路——83. Remove Duplicates from Sorted List

    哈哈,我又来了.昨天发现题目太简单就没有放上来,今天来了一道有序链表的题.题目如下: Given a sorted linked list, delete all duplicates such th ...

  5. LeetCode--LinkedList--83.Remove Duplicates from Sorted List(Easy)

    题目地址https://leetcode.com/problems/remove-duplicates-from-sorted-list/ 83. Remove Duplicates from Sor ...

  6. 83. Remove Duplicates from Sorted List【easy】

    83. Remove Duplicates from Sorted List[easy] Given a sorted linked list, delete all duplicates such ...

  7. 【一天一道LeetCode】#83. Remove Duplicates from Sorted List

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  8. 【一天一道LeetCode】#80. Remove Duplicates from Sorted Array II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Follow ...

  9. 26. Remove Duplicates from Sorted Array【easy】

    26. Remove Duplicates from Sorted Array[easy] Given a sorted array, remove the duplicates in place s ...

  10. 【LeetCode】82. Remove Duplicates from Sorted List II 解题报告(Python&C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/remove-du ...

随机推荐

  1. C# B站的弹幕提取

    要知道B站的弹幕位置 如果只考虑视频,B站的链接格式为:https://www.bilibili.com/video/av34042815.把av后面的数字看做是唯一标记即可. 既然能够把弹幕加载出来 ...

  2. pymongodb的使用和一个腾讯招聘爬取的案例

    一.在python3中操作mongodb 1.连接条件 安装好pymongo库 启动mongodb的服务端(如果是前台启动后就不关闭窗口,窗口关闭后服务端也会跟着关闭) 3.使用 import pym ...

  3. DVWA1.9平台XSS小结

    LOW级别就不写了...... 直接上中高级别(结合源码更好理解) 1.XSS Reflected(Medium) 从源码中可以清楚的看到,输入的<script>标签被过滤掉了,看清了,只 ...

  4. 分享个高精度IP定位

    https://www.opengps.cn/Data/IP/LocHighAcc.aspx

  5. 2019.3.13 final与static

    final 当使用final修饰类的时候,表示类不能被继承(就是extends后面不能再加它了) final 注意事项: 当使用final修饰时,该方法不能被子类重写 当一个方法被标记为private ...

  6. How to download Heavy Duty Diagnostic Caterpillar SIS 2018 software

    Maybe you find there are supplied Caterpillar SIS 2018 software free download in search engine, that ...

  7. python 学习笔记一——Python安装和IDLE使用

    好吧,一直准备学点啥,前些日子也下好了一些python电子书,但之后又没影了.年龄大了,就是不爱学习了.那就现在开始吧. 安装python 3 Mac OS X会预装python 2,Linux的大多 ...

  8. numpy.reshape使用条件

    np.array中的元素的个数,需要和转换的类型各个维度的乘积相等.如:\(6=2*3=1*2*3\) 另外,可以发现参数的对应关系为shape(num_dims, num_rows, num_col ...

  9. spark ALS 推荐算法参数说明

  10. Git学习手记

    直接使用github的客户端即可 1.简介 集中化的版本控制系统( Centralized Version Control Systems,简称 CVCS )应运而生.这类系统,诸如 CVS,Subv ...