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

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

  2. 【LeetCode】83. Remove Duplicates from Sorted List 解题报告(C++&Java&Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 判断相邻节点是否相等 使用set 使用列表 递归 日 ...

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

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

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

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

  5. 【LeetCode】80. Remove Duplicates from Sorted Array II (2 solutions)

    Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates":What if duplicate ...

  6. 【LeetCode】080. Remove Duplicates from Sorted Array II

    题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...

  7. 【leetcode】 26. Remove Duplicates from Sorted Array

    @requires_authorization @author johnsondu @create_time 2015.7.22 18:58 @url [remove dublicates from ...

  8. 【LeetCode】26. Remove Duplicates from Sorted Array 解题报告(Python&C++&Java)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 日期 [LeetCode] https:// ...

  9. 【LeetCode】80. Remove Duplicates from Sorted Array II 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

随机推荐

  1. PowerDesiger 15逆向生成工程E-R图及导出word表格

    应用环境:win8(64位)+oracle10g(32位)服务端+PowerDesigner15 需求:oracle数据库中的表结构是web工程框架hibernate 自动生成,现需要将数据库中已有的 ...

  2. c语言中argc和argv是什么意思?

    argc是参数个数,定义为intargv是字符串数组,存的是参数,定义为char**或者char* argv[]比如你编译好的程序为my.exe在命令行执行 my.exe 1 2 3那argc就是4, ...

  3. LabelMe图像数据集下载

    Download MATLAB Toolbox for the LabelMe Image Database 利用Matlab Toolbox工具箱下载图像库 一.下载Matlab Toolbox工具 ...

  4. testNG参数传递方式

    testNG传参数的两种方式(xml文件,@DataProvider) 使用testng.xml设置参数 参数在xml文件中可以在suite级别定义,也可以在test级别定义:testNG会尝试先在包 ...

  5. ubuntu 默认 进入 命令行

    图形模式下,首先进入终端:1. 运行 sudo vi/etc/default/grub2. 找到 GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”3.改为 GRUB_ ...

  6. C# 打印小票 POS

    C# 打印小票 POS 最近在写一个餐饮的收银系统,以前从来没有碰过打印机这玩意.感觉有些无从下手,在前面做报表时,总想找第三方的控件来用用,结果始终不行没搞定.没研究透,催得急没办法还是的动手自己写 ...

  7. SpringMVC结合ajaxfileupload.js实现文件无刷新上传

    直接看代码吧,注释都在里面 首先是web.xml <?xml version="1.0" encoding="UTF-8"?> <web-ap ...

  8. HTTP 请求方式: GET和POST的比较

    GET和POST是HTTP的两个常用方法.   什么是HTTP? 超文本传输协议(HyperText Transfer Protocol -- HTTP)是一个设计来使客户端和服务器顺利进行通讯的协议 ...

  9. VIM移动

    VIM移动   断断续续的使用VIM也一年了,会的始终都是那么几个命令,效率极低 前几个星期把Windows换成了Linux Mint,基本上也稳定了下来 就今晚,我已经下定决心开始新的VIM之旅,顺 ...

  10. maven命令大全

    1. mvn help:describe 你是否因为记不清某个插件有哪些goal而痛苦过,你是否因为想不起某个goal有哪些参数而苦恼,那就试试这个命令吧,它会告诉你一切的. 参数: 1. -Dplu ...