题目链接:https://leetcode.com/problems/remove-duplicates-from-sorted-list/
AC 0ms 100% Java:
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(head==null||head.next==null)
return head;
ListNode dummy=new ListNode(0);
ListNode t=dummy;
t.next=new ListNode(head.val);
t=t.next;
ListNode p=head.next;
int last=head.val;
while(p!=null){
if(last!=p.val){
last=p.val;
t.next=new ListNode(p.val);
t=t.next;
}
p=p.next;
}
return dummy.next;
}
}