解题思路:
同数组的删除重复元素。
26. 删除有序数组中的重复项
public ListNode deleteDuplicates(ListNode head) {
if(head == null) return null;
ListNode slow = head, fast = head;
while(fast != null){
if(fast.val != slow.val){
slow.next = fast;
slow = slow.next;
}
fast = fast.next;
}
//断开与后面重复元素的链接
slow.next = null;
return head;
}