删除有序链表中重复的元素-I
public ListNode deleteDuplicates (ListNode head) {
// write code here
ListNode cur=head;
while(cur!=null){
while(cur.next!=null&&cur.val==cur.next.val){
ListNode temp=cur.next.next; //这里牵扯到内存泄漏的问题,原回答为 cur.next=cur.next.next;
cur.next.next=null; cur.next=temp;
}
cur=cur.next;
}
return head;
}

浙公网安备 33010602011771号