//2 pointers
public ListNode deleteDuplicates(ListNode head) {
if(head == null)
return head;
ListNode dummy = new ListNode(0);
dummy.next = head;
ListNode pre = dummy;
ListNode cur = head;
while(cur!=null){
while(cur.next != null && pre.next.val == cur.next.val){
cur = cur.next;
}
if(pre.next==cur){
pre = pre.next;
}else{
pre.next = cur.next;
}
cur = cur.next;
}
return dummy.next;
}
refer: http://blog.csdn.net/linhuanmars/article/details/24389429