力扣 中等 82.删除排序链表中的重复元素 II

文章目录

题目介绍

题解

只需在83题基础上加一个while循环即可

java 复制代码
class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode dummy = new ListNode(101, head);
        ListNode cur = dummy;
        while (cur.next != null && cur.next.next != null) {
            int val = cur.next.val;
            if (cur.next.next.val == val) {
                while (cur.next != null && cur.next.val == val) {
                    cur.next = cur.next.next;
                }
            } else {
                cur = cur.next;
            }
        }
        return dummy.next;
    }
}
相关推荐
lightqjx23 分钟前
【算法】二分算法
c++·算法·leetcode·二分算法·二分模板
行百里er1 小时前
优雅应对异常,从“try-catch堆砌”到“设计驱动”
java·后端·代码规范
ms_27_data_develop1 小时前
Java枚举类、异常、常用类
java·开发语言
xiaohe071 小时前
Spring Boot 各种事务操作实战(自动回滚、手动回滚、部分回滚)
java·数据库·spring boot
代码飞天1 小时前
wireshark的高级使用
android·java·wireshark
ic爱吃蓝莓1 小时前
数据结构 | HashMap原理
数据结构·学习·算法·链表·哈希算法
灰色小旋风1 小时前
力扣21 合并两个有序链表(C++)
c++·leetcode·链表
gechunlian882 小时前
Spring Boot中的404错误:原因、影响及处理策略
java·spring boot·后端
岁岁种桃花儿2 小时前
AI超级智能开发系列从入门到上天第四篇:AI应用方案设计
java·服务器·开发语言
架构师沉默2 小时前
Java 终于有自己的 AI Agent 框架了?
java·后端·架构