import java.util.*;

/*

  • public class ListNode {
  • int val;
  • ListNode next = null;
  • } */

public class Solution { /** * * @param head ListNode类 * @return ListNode类 */ public ListNode deleteDuplicates (ListNode head) { ListNode dummy = new ListNode(0); dummy.next = head; ListNode pre = dummy; ListNode p = head; while(p != null && p.next != null){ if(p.val == p.next.val){ while(p.next != null && p.val == p.next.val){ p = p.next; } pre.next = p.next; p= p.next; }else{ pre = p; p = p.next; } } return dummy.next; // write code here } }