forked from geekxh/hello-algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution.java
39 lines (36 loc) · 868 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* @author Anonymous
* @since 2019/11/21
*/
/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}
*/
public class Solution {
/**
* 删除链表重复的节点
* @param pHead 链表头节点
* @return 删除节点后的链表
*/
public ListNode deleteDuplication(ListNode pHead) {
if (pHead == null || pHead.next == null) {
return pHead;
}
if (pHead.val == pHead.next.val) {
if (pHead.next.next == null) {
return null;
}
if (pHead.next.next.val == pHead.val) {
return deleteDuplication(pHead.next);
}
return deleteDuplication(pHead.next.next);
}
pHead.next = deleteDuplication(pHead.next);
return pHead;
}
}