当前位置:网站首页>LeetCode 83. 删除排序链表中的重复元素
LeetCode 83. 删除排序链表中的重复元素
2022-08-10 11:09:00 【水菜笔】
原题网址:https://leetcode.cn/problems/remove-duplicates-from-sorted-list/
排好序的链表,删除重入元素。
public ListNode deleteDuplicates(ListNode head) {
if(head == null || head.next == null) {
return head;
}
ListNode cur = head;
// 遍历的顺序一定要和比较顺序一致。
// 我以前的想法是当前和前一个比,值不一样,连接上,否则,就像后找
// 这样相当于遍历是从前向后遍历,但是判断是跟前一个比;容易出错。
while(cur != null && cur.next != null) {
if(cur.val == cur.next.val) {
cur.next = cur.next.next;
} else {
cur = cur.next;
}
}
return head;
}
边栏推荐
- Where can I view the version record of WeChat applet submission review history?
- 力扣练习——58 验证二叉搜索树
- 电脑怎么设置屏幕息屏时间(日常使用分享)
- 蔚来-软件开发工程师一面记录
- 阻塞 非阻塞 poll机制 异步
- 【勇敢饭饭,不怕刷题之链表】有序链表的合并
- Programmers pursue technology to consolidate basic learning route suggestions
- 老板加薪!看我做的WPF Loading!!!
- rider内Mono脚本找不到引用资源
- 面试官:项目中 Dao、Service、Controller、Util、Model 怎么划分的?
猜你喜欢

Redis设计与实现

做自媒体月入几万?博主们都在用的几个自媒体工具

老板加薪!看我做的WPF Loading!!!

LeetCode50天刷题计划(Day 17—— 下一个序列(14.50-16.30)

VSCode远程连接服务器报错:Could not establish connection to “xxxxxx”的可能错误原因及解决

LeetCode50天刷题计划(Day 18—— 搜索旋转排序数组(8.50-12.00)

gpu-admission 源码分析

自媒体爆款标题怎么写?手把手教你写热门标题

Alibaba最新神作!耗时182天肝出来1015页分布式全栈手册太香了

3款不同类型的自媒体免费工具,有效提高创作、运营效率
随机推荐
力扣练习——62 有效的数独
【Untitled】
微信小程序提交审核历史版本记录从哪里查看
使用哈工大LTP测试分词并且增加自定义字典
Flutter气泡框实现
单目操作符(含原码反码补码转换)
Pulling drills - 56 Finding the right interval
POJ 3101 Astronomy (Mathematics)
从脚本到剪辑,影像大师亲授的后期制作秘籍
阻塞 非阻塞 poll机制 异步
力扣练习——63 找到字符串中所有字母异位词
Introduction to Software Architecture
暑期总结4
【机器学习】浅谈正规方程法&梯度下降
Buckle exercise - rectangular area does not exceed the maximum value of K and (hard)
Analysis of the name matching process between the LCD driver and the device (Tiny4412)
OPNsense安装配置Zenarmor
基于UiAutomator2+PageObject模式开展APP自动化测试实战
Analysis of the implementation principle of UUID from the perspective of source code
Chapter 22 Source Code File REST API Reference (4)