82. Remove Duplicates from Sorted List II

    xiaoxiao2025-03-02  20

    找对条件,

    public class Solution { public ListNode deleteDuplicates(ListNode head) { if(head==null) return head; ListNode newhead=new ListNode(0); ListNode pre=newhead; pre.next=head; // newhead.next=head; // ListNode cur=newhead; while(head!=null){ while(head.next!=null&&head.val==head.next.val){ head=head.next; } if(pre.next==head) pre=pre.next; else { pre.next=head.next; } head=head.next; } return newhead.next; } }

    转载请注明原文地址: https://ju.6miu.com/read-1296814.html
    最新回复(0)