// 题目描述 // 在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针。 // 例如,链表1->2->3->3->4->4->5 处理后为 1->2->5 public static class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; } } public static ListNode deleteDuplication(ListNode pHead) { if (pHead==null){ return pHead; } ListNode result = new ListNode(0); ListNode next = pHead.next; result.next=pHead; ListNode pre = result; while (pHead!=null&&pHead.next!=null){ if (pHead.val==next.val){ while (next!=null&&pHead.val==next.val){ next = next.next; } pre.next=next; pHead=next; if (next!=null){ next = next.next; } }else{ pre = pHead; pHead = pHead.next; next = next.next; } } return result.next; }