import java.util.*;
/*
* public class ListNode {
* int val;
* ListNode next = null;
* }
*/
public class Solution {
/**
*
* @param head ListNode类
* @return ListNode类
*/
public ListNode deleteDuplicates (ListNode head) {
// write code here
if(head==null) return null;
ListNode res=new ListNode(-1);
ListNode cur=res;
res.next=head;
while(cur.next != null && cur.next.next != null){//两个以上结点
//遇到相邻两个节点值相同
if(cur.next.val == cur.next.next.val){
int temp = cur.next.val;//保存相同的结点值
//将所有相同的都跳过
while (cur.next != null && cur.next.val == temp)//只要等于相同的节点值,就跳过
cur.next = cur.next.next;
}
else
cur = cur.next;
}
//返回时去掉表头
return res.next;
}
}