[leetcode]83.Remove Duplicates from Sorted List
题目
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相关推荐
- [勇者闯LeetCode] 83. Remove Duplicates from Sorted List
[勇者闯LeetCode] 83. Remove Duplicates from Sorted List Description Given a sorted linked list, delete ...
- LeetCode 83. Remove Duplicates from Sorted List
题目: Given a sorted linked list, delete all duplicates such that each element appear only once. For e ...
- 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++> 给出排序好的 ...
- Leetcode OJ: Remove Duplicates from Sorted Array I/II
删除排序数组重复元素,先来个简单的. Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates i ...
- LeetCode 80. Remove Duplicates from Sorted Array II
80. Remove Duplicates from Sorted Array II My Submissions QuestionEditorial Solution Total Accepted: ...
- LeetCode之Remove Duplicates from Sorted Array II
1.题目 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ...
- leetcode python3 简单题83. Remove Duplicates from Sorted List
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第八十三题 (1)题目 英文: Given a sorted linked list ...
- 【leetcode】Remove Duplicates from Sorted Array
题目:Given a sorted array, remove the duplicates in place such that each element appear only once and ...
- LeetCode之Remove Duplicates from Sorted Array
1.题目 Given a sorted array, remove the duplicates in place such that each element appear only once an ...
最新文章
- “解决方案资源管理器”中不能自动选择正在编辑的文档
- CentOS7 打包RPM 升级OpenSSH8.3
- apache 源代码安装
- ARKit应用超300万次安装,排第一的是一款养成游戏
- JVM运行时数据区---方法区(演变和垃圾回收)
- ACCESS的Ole对象读取
- servlet——请求乱码问题解决
- BZOJ2212——线段树合并
- java什么是对象如何创建对象_java对象的创建过程是什么
- 呼叫我,或异步REST
- Linux 系统进程、线程之间的爱恨纠葛...
- hdu1054(最小顶点覆盖)
- python数组删除最后一个元素_删除numpy数组中的最后一个元素
- es6 实例:Web 服务的客户端
- 中国象棋棋子及棋盘的绘制
- linux vim 终端 行首 行尾_不会vi/vim,看这一篇足矣
- Spring MVC中静态资源加载
- python pyz_python-3.x – 如何在Alpine Linux容器上安装pyz...
- xshell xftp 工具免费版本免费下载
- Java连接数据库代码
热门文章
- adb命令实现一些有趣的功能
- 【译】Byzantine Fault Tolerance in Proof-of-stake protocols
- ICLR 2017 | GAN Missing Modes 和 GAN
- Android5.0源码分析—— Zygote进程分析
- Android系统的启动流程简要分析
- 内核 kmap_atomic分析
- php 云技术,什么叫云技术?
- JZOJ 5982. 【WC2019模拟12.27】路径排序
- c语言中return的作用_C语言简介
- 这台计算机怎么磁盘清理,电脑硬盘满了怎么清理(教你3招彻底清理内存,瞬间多出几十个G)...