java:
class Solution {
public ListNode deleteDuplicates(ListNode head) {
if (head == null)
return head;
ListNode pre = new ListNode(-1);
ListNode res = pre;
while (head != null) {
while (head.next != null && head.val == head.next.val) {
head = head.next;//head停留在最后一个重复节点上
}
pre.next = head;
pre = head;//pre要移动
head = head.next;
}
return res.next;
}
}