import java.util.*; /* * public class ListNode { * int val; * ListNode next = null; * } */ public class Solution { /** * * @param head ListNode类 * @return ListNode类 */ public ListNode deleteDuplicates (ListNode head) { if(head == null || head.next == null) return head ; ListNode pre = new ListNode(1001) ; pre.next = head ; ListNode slow_pre = pre ; ListNode slow = head ; ListNode fast = head.next ; while(fast != null) { if(fast.val == slow.val) { fast = fast.next ; if(fast == null || fast.val != slow.val) { slow_pre.next = fast ; slow = fast ; if(fast != null) { fast = fast.next ; } } } else { slow_pre = slow ; slow = slow.next ; fast = fast.next ; } } return pre.next ; } }