-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path56.java
More file actions
38 lines (35 loc) · 820 Bytes
/
56.java
File metadata and controls
38 lines (35 loc) · 820 Bytes
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
/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}
*/
public class Solution {
public ListNode deleteDuplication(ListNode pHead)
{
if(pHead==null || pHead.next==null) return pHead;
ListNode first=new ListNode(-1);
first.next=pHead;
ListNode pre=pHead;
ListNode last=first;
while(pre!=null && pre.next!=null)
{
if(pre.val==pre.next.val)
{
int value=pre.val;
while(pre!=null && pre.val==value)
pre=pre.next;
last.next=pre;
}
else
{
last=pre;
pre=pre.next;
}
}
return first.next;
}
}