力扣 中等 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;
    }
}
相关推荐
xieliyu.2 小时前
Java算法精讲:双指针(三)
java·开发语言·算法
明夜之约2 小时前
Spring Boot 自动装配源码
java·spring boot·后端
Leaton Lee2 小时前
Spring Boot分层架构详解:从Controller到Service再到Mapper的完整流程
java·spring boot·后端·架构
Jinkxs2 小时前
Resilience4j- 与 Spring Boot 快速集成:自动配置与基础注解使用
java·spring boot·后端
辣机小司2 小时前
【踩坑记录:Spring Boot 配置文件读取值不一致?警惕 YAML 的“八进制陷阱”与 SnakeYAML 版本之谜】
java·spring boot·后端·yaml·踩坑记录
fangdengfu1233 小时前
ES分析系统各个服务日志占用量
java·前端·elasticsearch
云烟成雨TD3 小时前
Spring AI 1.x 系列【51】可观测性技术选型
java·人工智能·spring
星越华夏3 小时前
ESP32-CAM图像传输项目说明文档
java·后端·struts·esp32
如竟没有火炬4 小时前
最大矩阵——单调栈
数据结构·python·线性代数·算法·leetcode·矩阵
Jinkxs4 小时前
Java 跨域14-Java 与区块链(Hyperledger)集成
java·开发语言·区块链