2019-11-02 12:07:41 +08:00
|
|
|
# 18.2 删除链表中重复的结点
|
|
|
|
|
2022-01-07 09:00:01 +00:00
|
|
|
[牛客网](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)
|
2019-11-02 12:07:41 +08:00
|
|
|
|
|
|
|
## 题目描述
|
|
|
|
|
2022-01-07 09:00:01 +00:00
|
|
|
\
|
|
|
|
|
2019-11-02 12:07:41 +08:00
|
|
|
|
|
|
|
## 解题描述
|
|
|
|
|
|
|
|
```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)
|
|
|
|
next = next.next;
|
|
|
|
return deleteDuplication(next);
|
|
|
|
} else {
|
|
|
|
pHead.next = deleteDuplication(pHead.next);
|
|
|
|
return pHead;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|