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.

思路:

用两个指针,一个在前,一个在后,比较两个结点的值,如果相等,后一个指针后移,再比较。

如果不相等,则前一个指针指向后一个指针,然后同时后移。

ListNode* deleteDuplicates(ListNode* head){if (head == NULL || head->next == NULL) return head;        ListNode* p = head, *q = head->next;while (q != NULL){if (p->val == q->val){}else{p->next = q;p = q;}q = q->next;}p->next = q;return head;}

转载于:https://www.cnblogs.com/hellowooorld/p/6679588.html

[leetcode-83-Remove Duplicates from Sorted List]相关推荐

  1. [勇者闯LeetCode] 83. Remove Duplicates from Sorted List

    [勇者闯LeetCode] 83. Remove Duplicates from Sorted List Description Given a sorted linked list, delete ...

  2. [leetcode]83.Remove Duplicates from Sorted List

    题目 Given a sorted linked list, delete all duplicates such that each element appear only once. Exampl ...

  3. LeetCode 83. Remove Duplicates from Sorted List

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

  4. LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] c++

    LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] <c++> 给出排序好的 ...

  5. Leetcode OJ: Remove Duplicates from Sorted Array I/II

    删除排序数组重复元素,先来个简单的. Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates i ...

  6. LeetCode 80. Remove Duplicates from Sorted Array II

    80. Remove Duplicates from Sorted Array II My Submissions QuestionEditorial Solution Total Accepted: ...

  7. LeetCode之Remove Duplicates from Sorted Array II

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

  8. leetcode python3 简单题83. Remove Duplicates from Sorted List

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第八十三题 (1)题目 英文: Given a sorted linked list ...

  9. 【leetcode】Remove Duplicates from Sorted Array

    题目:Given a sorted array, remove the duplicates in place such that each element appear only once and ...

  10. LeetCode之Remove Duplicates from Sorted Array

    1.题目 Given a sorted array, remove the duplicates in place such that each element appear only once an ...

最新文章

  1. php 开启mysql_php如何开启mysqli扩展
  2. python二维游戏编程 超级大脑_超级大脑教练 - 主页
  3. 内核代号101 — 动手写自己的内核
  4. H5 Canvas刮刮乐
  5. 【渝粤题库】陕西师范大学202321投资银行学 作业(专升本)
  6. 修改linux绑定的域名,手工修改linux系统下DA面板绑定的域名
  7. elasticsearch date_MySQL数据实时增量同步到Elasticsearch
  8. linux 服务器(CentOS7)搭建PHP环境+SSH配置+服务器文件上传配置
  9. mysql 实例与用户_MySQL(17):用户登录实例
  10. python基础0304
  11. xxl-job使用笔记
  12. Educoder Matplotlib和Seaborn三维图 第2关:曲面三角剖分
  13. Symmetric Tree
  14. append追加的html中富文本失效,jquery append 动态添加的元素事件on 不起作用的解决方案...
  15. 最好用的PDF软件汇总
  16. 高中数学竞赛书籍推荐
  17. 数学建模(NO.9斯皮尔曼相关系数)
  18. python语言月份缩写_[宜配屋]听图阁
  19. visual studio code打开预览.md文件
  20. Android P SELinux (二) 开机初始化与策略文件编译过程

热门文章

  1. 如何发布第一个属于自己的npm包
  2. sublime快捷键设置
  3. 数字三角形_递归_递推(动态规划)
  4. 修改Chrome默认搜索引擎为Google.com
  5. OVS-vsctl的帮助文件的中文版
  6. 基础才是重中之重~如何整理BLL与DAL层的文件
  7. (整理)C/C++野指针
  8. DWR学习笔记 - Hello World
  9. Sql server在另一台服务器,在Visual Studio 中没问题,IIS中 提示“在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。。。。”...
  10. linux中的设备名称和设备号