【剑指Offer】删除链表中重复的结点 Posted on 2017-09-07 | In Algorithm , 剑指Offer 题目在一个排序的链表中,如何删除重复的结点? 实现12345678public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }} 123456789101112131415161718192021222324252627public ListNode deleteDuplication(ListNode pHead) { if (pHead == null) return null; ListNode current = pHead; ListNode prev = null; while (current != null && current.next != null) { if (current.next.val > current.val) { prev = current; current = current.next; } else { while (current.next != null && current.next.val == current.val) current = current.next; current = current.next; if (prev != null) prev.next = current; else pHead = current; } } return pHead;}