public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 * @return ListNode类 */ public ListNode deleteDuplicates (ListNode head) { // write code here if(head==null||head.next==null) return head; ListNode nhead=new ListNode(-1); nhead.next=head; ListNode p=nhead; while(p.next!=null){ while(p.val==p.next.val&&p.next!=null){ if(p.next.next!=null) p.next=p.next.next; else { p.next=null;break; } } if(p.next!=null)//没有这句话会一直通过不了 p=p.next; } return nhead.next; }