当前位置:网站首页>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;
}
边栏推荐
- mysql appears: ERROR 1524 (HY000): Plugin '123' is not loaded
- 从脚本到剪辑,影像大师亲授的后期制作秘籍
- LeetCode_152_乘积最大子数组
- 今天面了个腾讯拿38K出来的大佬,让我见识到了基础的天花板
- Kyligence 通过 SOC 2 Type II 审计,以可信赖的企业级产品服务全球客户
- Codeforces 862 C. Mahmoud and Ehab and the xor (技巧)
- ViT结构详解(附pytorch代码)
- 软件架构简介
- 项目部署、
- APP automation testing practice based on UiAutomator2+PageObject mode
猜你喜欢
如何使用工程仪器设备在线监测管理系统
建校仅11年就入选“双一流” ,这所高校是凭什么做到的?
Module 9 - Designing an e-commerce seckill system
为什么Redis很快
LAXCUS分布式操作系统安全管理
使用哈工大LTP测试分词并且增加自定义字典
零基础想自学软件测试,有没有大佬可以分享下接下来的学习书籍和路线?
VSCode remote connection server error: Could not establish connection to "xxxxxx" possible error reasons and solutions
[E-commerce operation] Do you really understand social media marketing (SMM)?
自媒体爆款标题怎么写?手把手教你写热门标题
随机推荐
LeetCode50天刷题计划(Day 19—— 在排序数组中查找元素的第一个和最后一个位置(9.10-10.40)
AUTOCAD——减少样条曲线控制点数、CAD进阶练习(三)
Do self-media monthly income tens of thousands?Several self-media tools that bloggers are using
Stroke Practice - 62 Valid Sudokus
Where can I view the version record of WeChat applet submission review history?
Centos7环境使用Mysql离线安装包安装Mysql5.7
程序员追求技术夯实基础学习路线建议
The brave rice rice, does not fear the brush list of 】 list has a ring
阻塞 非阻塞 poll机制 异步
【勇敢饭饭,不怕刷题之链表】有序链表的合并
POJ 3101 Astronomy (Mathematics)
HDU 4135: Co-prime (the principle of inclusion and exclusion)
POJ 1026 Cipher (Permutation Groups)
SQL优化最强总结 (建议收藏~)
三个绘图工具类详解Paint(画笔)Canvas(画布)Path(路径)
有哪些好用的性能测试工具推荐?性能测试报告收费标准
Clicking Exercise - 64 Longest Harmonic Subsequences
态路小课堂丨如何为CXP光模块选择光纤跳线?
LCD驱动端与设备端名称匹配过程分析(Tiny4412)
LeetCode 61. 旋转链表