删除有序链表中重复的元素-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;
    }
posted @ 2023-11-22 21:55  Chenyi_li  阅读(1)  评论(0编辑  收藏  举报