For example,
Given
Given
1->1->2
, return
1->2
.
Given 1->1->2->3->3
, return 1->2->3
.
public class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(head==null) return null;
ListNode a = head;
while(a.next!=null){
if(a.val==a.next.val){
a.next = a.next.next;
}else{
a = a.next;
}
}
return head;
}
}