这道题很简单属于一遍ac题,放两个指针,一个在前,一个在后,只要他们俩值不同,就连起来,不管中间有什么。。。
public class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(head==null)return head;
if(head.next==null)return head;
ListNode first = head;
ListNode second = head.next;
while(second!=null){
if(first.val==second.val){
second = second.next;
}else{
first.next = second;
first = second;
second = first.next;
}
}
first.next = second;
return head;
}
}