/*
在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,
重复的结点不保留,返回链表头指针。 例如,链表1->2->3->3->4->4->5 处理后为 1->2->5
*/
public class Class61 {
public class ListNode{
int val;
ListNode next = null;
ListNode(int val){
this.val = val;
}
}
public ListNode deleteDuplication(ListNode head){
if(head == null || head.next == null){
return head;
}
ListNode first = new ListNode(0);
first.next = head;
ListNode pre = first;
ListNode current = head;
while(current != null){
if(current.next != null && current.val == current.next.val){
while(current.next != null && current.val == current.next.val){
current = current.next;
}
pre.next = current.next;
current = current.next;
}else{
pre = pre.next;
current = current.next;
}
}
return first.next;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}