For example,
Given1->1->2, return1->2.
Given1->1->2->3->3, return1->2->3.
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(head==null||head.next==null) return head;
ListNode cur = head.next;
ListNode pre = head;
head.next = null;
while(cur!=null){
if(pre.val==cur.val){
cur = cur.next;
}
else{
pre.next = cur;
pre = cur;
cur = cur.next;
pre.next = null;
}
}
return head;
}
}