当前位置:网站首页>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;
}
边栏推荐
- LeetCode 21. 合并两个有序链表
- POJ 3101 Astronomy (Mathematics)
- 再有人问你分布式事务,把这篇扔给他
- 【Untitled】
- std::move()
- 老板加薪!看我做的WPF Loading!!!
- Does your child lack self-discipline?Ape Counseling: Pay attention to "blank" in the schedule to give children more control
- OPNsense安装配置Zenarmor
- VSCode remote connection server error: Could not establish connection to "xxxxxx" possible error reasons and solutions
- 使用.NET简单实现一个Redis的高性能克隆版(六)
猜你喜欢
随机推荐
孩子自律性不够?猿辅导:计划表要注意“留白”给孩子更多掌控感
今天面了个腾讯拿38K出来的大佬,让我见识到了基础的天花板
Clicking Exercise - 64 Longest Harmonic Subsequences
单目操作符(含原码反码补码转换)
什么是幂等性?四种接口幂等性方案详解!
[E-commerce operation] Do you really understand social media marketing (SMM)?
Redis常用命令
程序员追求技术夯实基础学习路线建议
不止跑路,拯救误操作rm -rf /*的小伙儿
石墨文档打开文档时快速定位到上次写的位置
LeetCode 445. 两数相加 II
三个绘图工具类详解Paint(画笔)Canvas(画布)Path(路径)
ViT结构详解(附pytorch代码)
Codeforces 862 C. Mahmoud and Ehab and the xor (技巧)
电脑怎么设置屏幕息屏时间(日常使用分享)
力扣练习——62 有效的数独
老板加薪!看我做的WPF Loading!!!
Where can I view the version record of WeChat applet submission review history?
LeetCode 138. 复制带随机指针的链表
mysql出现:ERROR 1524 (HY000): Plugin ‘123‘ is not loaded