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.

class Solution {
public:
ListNode *deleteDuplicates(ListNode *head) {
if(!head) return head; ListNode *previous = head;
ListNode *current = head->next;
while(current)
{
if(current->val == previous->val)
{
previous->next = current->next;
}
else
{
previous = previous->next;
} current = current->next;
}
return head;
}
};

83. Remove Duplicates from Sorted List (List)的更多相关文章

  1. leetcode 203. Remove Linked List Elements 、83. Remove Duplicates from Sorted List 、82. Remove Duplicates from Sorted List II(剑指offer57 删除链表中重复的结点)

    203题是在链表中删除一个固定的值,83题是在链表中删除重复的数值,但要保留一个:82也是删除重复的数值,但重复的都删除,不保留. 比如[1.2.2.3],83题要求的结果是[1.2.3],82题要求 ...

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

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

  3. <LeetCode OJ> 83. Remove Duplicates from Sorted List

    83. Remove Duplicates from Sorted List Total Accepted: 94387 Total Submissions: 264227 Difficulty: E ...

  4. [LeetCode] 83. Remove Duplicates from Sorted List 移除有序链表中的重复项

    Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1 ...

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

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

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

  7. 83. Remove Duplicates from Sorted List

    Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...

  8. 【LeetCode】83 - Remove Duplicates from Sorted List

    Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...

  9. Java [Leetcode 83]Remove Duplicates from Sorted List

    题目描述: Given a sorted linked list, delete all duplicates such that each element appear only once. For ...

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

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

随机推荐

  1. lapis http verb 处理

    1. 同一个url 包含不同的请求(respond_to  进行解决) // 路由格式 match ,通过respond_to 进行实际的http verb 处理 local lapis = requ ...

  2. Google Chrome 总提示flash插件过期,用命令行模式解决

    目标那改成:"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --args --allow-outdate ...

  3. vc中edit控件使用总结

    通过类向导可以生成两种类成员变量,一种是cstring类型,一种是cedit类型.在程序中使用时如果只是简单的获取 edit控件内容,或设置简单的内容建议使用cstring类型成员变量.示例:CStr ...

  4. CentOS下搭建.NET Core项目运行环境

    系统版本:CentOS 7.3 运行环境:.NET Core 数据库:MySQL 进程守护:Supervisor .NET Core环境 安装CentOS中.NET Core依赖库 yum insta ...

  5. struts2学习(4)struts2核心知识III

    一.result配置: result - name 就是前面返回的值,success,error等. type: dispatcher. 默认是这个,底层是jsp的forward: redirect: ...

  6. DynamicConverter

    folly/DynamicConverter.h When dynamic objects contain data of a known type, it is sometimes useful t ...

  7. 前端性能优化:gzip压缩文件传输数据

    一.文件压缩的好处 前端生产环境中将js.css.图片等文件进行压缩的好处显而易见,通过减少数据传输量减小传输时间,节省服务器网络带宽,提高前端性能. 二.http协议如何支持压缩文件的传输 1.浏览 ...

  8. Metasploit对安卓手机的攻击

    首先要kali进行内网穿透,可参考http://www.cnblogs.com/sch01ar/p/7562954.html 首先生成一个apk木马 命令:msfvenom -p android/me ...

  9. Running command-line BLAST

    Ubuntu安装BLAST 2014-02-09 10:45:03|  分类: Linux/Ubuntu|举报|字号 订阅     下载LOFTER我的照片书  |     very easy! su ...

  10. 十年Java架构师分享

    看到一篇十年java架构师分享需要掌握的技术点,有时间对照一下,好好学习一下. ------------------------------------------------------------ ...