力扣 中等 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;
    }
}
相关推荐
鹿角片ljp1 小时前
LeetCode 64:最小路径和复盘|二维 DP 与 ACM 模式完整写法
java·数据结构·算法
泡海椒2 小时前
PDF 表格样式优化:jquick-pdf 边框、圆角、背景色
java·开发语言·pdf
景熙55234 小时前
15.Java 8 Stream 流入门到实战
java·开发语言·数据结构
wno7044 小时前
Spring Security权限控制
java·python·spring
杨运交5 小时前
[071][验证码模块]基于Spring拦截器的验证码认证设计思想
java·后端·spring
Geek-Chow5 小时前
CountDownLatch in Java
java
圣保罗的大教堂5 小时前
leetcode 835. 图像重叠 中等
leetcode
SL_staff5 小时前
从RBAC到场景化授权:《无忧·企业文档》三级权限模型的技术实践解析
java·开源·产品
传奇开心果编程6 小时前
【springboot基础语法学与练】第 1 课:从零开始
java·spring boot·后端·学习