题目描述:82. 删除排序链表中的重复元素 II
package p3.链式结构;
public class Solution82 {
public ListNode deleteDuplicates(ListNode head) {
if (head == null || head.next == null) {
return head;
}
ListNode dummy = new ListNode(0);
dummy.next = head;
ListNode pre = dummy;
ListNode cur = head;
while (cur != null && cur.next != null) {
if (cur.val != cur.next.val) {
pre = cur;
cur = cur.next;
} else {
ListNode next = cur.next.next;
while (next != null && next.val == cur.val) {
next = next.next;
}
pre.next = next;
cur = next;
}
}
return dummy.next;
}
}