`在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针
public class DeleteDupcation {
public ListNode deleteDuplication(ListNode pHead){
if(pHead==null||pHead.next==null){
return pHead;
}
ListNode head=new ListNode(Integer.MIN_VALUE);
head.next=pHead;
ListNode pre=head;
ListNode cur=head.next;
while(cur!=null){
if(cur.next!=null&&cur.val==cur.next.val){
while(cur.next!=null&&cur.val==cur.next.val){
cur=cur.next;
}
cur=cur.next;
pre.next=cur;
}else{
pre=cur;
cur=cur.next;
}
}
return head.next;
}
}