首页 > 其他 > 详细

Remove Duplicates from Sorted List

时间:2015-04-08 06:42:45      阅读:155      评论:0      收藏:0      [点我收藏+]

看了别人讨论,双指针比较方便http://www.cnblogs.com/springfor/p/3862042.html

public class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        if(head==null|| head.next==null) return head;
        ListNode h = new ListNode(-1);
        h.next = head;
        ListNode l1 = head;
        ListNode l2 = l1.next;
        while(l2!=null){
            while(l2!=null && l1.val==l2.val){
                l2 = l2.next;
            }
            l1.next = l2;
            l1=l1.next;
        }
        return h.next;
    }
}

 

Remove Duplicates from Sorted List

原文:http://www.cnblogs.com/jiajiaxingxing/p/4401279.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!