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(101) ; pre.next = head ; ListNode slow = pre ; ListNode fast = head ; while(fast != null) { if(fast.val == slow.val) { fast = fast.next ; if(fast == null || fast.val != slow.val) { slow.next = fast ; } } else { slow = slow.next ; fast = fast.next ; } } return pre.next ; } }