题目

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

Example 1:

Input: 1->1->2
Output: 1->2
Example 2:

Input: 1->1->2->3->3
Output: 1->2->3

解法

思路

其实刚看到这道题,我直接想到的是[leetcode]26.Remove Duplicates from Sorted Array这道题的思路,所以设置了一个快指针和一个慢指针。

代码

/*** Definition for singly-linked list.* public class ListNode {*     int val;*     ListNode next;*     ListNode(int x) { val = x; }* }*/
class Solution {public ListNode deleteDuplicates(ListNode head) {if(head == null) return null;ListNode fast = head;ListNode slow = head;while(fast != null) {if(slow.val == fast.val)fast = fast.next;else{slow.next = fast;slow = slow.next;}}slow.next = null; return head;}
}

转载于:https://www.cnblogs.com/shinjia/p/9734386.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. For e ...

  3. 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++> 给出排序好的 ...

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

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

  5. LeetCode 80. Remove Duplicates from Sorted Array II

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

  6. LeetCode之Remove Duplicates from Sorted Array II

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

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

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

  8. 【leetcode】Remove Duplicates from Sorted Array

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

  9. 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. “解决方案资源管理器”中不能自动选择正在编辑的文档
  2. CentOS7 打包RPM 升级OpenSSH8.3
  3. apache 源代码安装
  4. ARKit应用超300万次安装,排第一的是一款养成游戏
  5. JVM运行时数据区---方法区(演变和垃圾回收)
  6. ACCESS的Ole对象读取
  7. servlet——请求乱码问题解决
  8. BZOJ2212——线段树合并
  9. java什么是对象如何创建对象_java对象的创建过程是什么
  10. 呼叫我,或异步REST
  11. Linux 系统进程、线程之间的爱恨纠葛...
  12. hdu1054(最小顶点覆盖)
  13. python数组删除最后一个元素_删除numpy数组中的最后一个元素
  14. es6 实例:Web 服务的客户端
  15. 中国象棋棋子及棋盘的绘制
  16. linux vim 终端 行首 行尾_不会vi/vim,看这一篇足矣
  17. Spring MVC中静态资源加载
  18. python pyz_python-3.x – 如何在Alpine Linux容器上安装pyz...
  19. xshell xftp 工具免费版本免费下载
  20. Java连接数据库代码

热门文章

  1. adb命令实现一些有趣的功能
  2. 【译】Byzantine Fault Tolerance in Proof-of-stake protocols
  3. ICLR 2017 | GAN Missing Modes 和 GAN
  4. Android5.0源码分析—— Zygote进程分析
  5. Android系统的启动流程简要分析
  6. 内核 kmap_atomic分析
  7. php 云技术,什么叫云技术?
  8. JZOJ 5982. 【WC2019模拟12.27】路径排序
  9. c语言中return的作用_C语言简介
  10. 这台计算机怎么磁盘清理,电脑硬盘满了怎么清理(教你3招彻底清理内存,瞬间多出几十个G)...