Remove Duplicates from Sorted List

来源:互联网 发布:网络运维 英文缩写 编辑:程序博客网 时间:2024/06/06 19:09

思路较简单,主要考虑边界情况。

    public ListNode deleteDuplicates(ListNode head) {        if(head==null) return null;        ListNode priorNode=head;        ListNode nextNode=head.next;        while(nextNode!=null){            while(nextNode!=null&&nextNode.val==priorNode.val){                nextNode=nextNode.next;            }            priorNode.next=nextNode;            if(nextNode!=null){                priorNode=nextNode;                nextNode=nextNode.next;            }        }        return head;    }
原创粉丝点击