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 || head.next == null) return head;
ListNode fore = head;
//单指针模拟
while (fore.next != null) {
if (fore.val == fore.next.val) {
//若重复 跳过第二个指针
fore.next = fore.next.next;
} else {
//不重复则继续便利
fore = fore.next;
}
}
return head;
}
}

京公网安备 11010502036488号