Update 18.2 删除链表中重复的结点.md

题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
CyC2018
2026-10-28 13:45:03 +08:00
parent b4c0ba5c3b
commit d8ee3b592e
+10 -10
View File
@@ -1,6 +1,6 @@
# 18.2 删除链表中重复的结点
[牛客网](https://www.nowcoder.com/practice/fc533c45b73a41b0b44ccba763f866ef?tpId=13&tqId=11209&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
[Leetcode](https://leetcode.cn/problems/remove-duplicates-from-sorted-list-ii/)
## 题目描述
@@ -9,17 +9,17 @@
## 解题描述
```java
public ListNode deleteDuplication(ListNode pHead) {
if (pHead == null || pHead.next == null)
return pHead;
ListNode next = pHead.next;
if (pHead.val == next.val) {
while (next != null && pHead.val == next.val)
public ListNode deleteDuplicates(ListNode head) {
if (head == null || head.next == null)
return head;
ListNode next = head.next;
if (head.val == next.val) {
while (next != null && head.val == next.val)
next = next.next;
return deleteDuplication(next);
return deleteDuplicates(next);
} else {
pHead.next = deleteDuplication(pHead.next);
return pHead;
head.next = deleteDuplicates(head.next);
return head;
}
}
```