码迷,mamicode.com
首页 > 其他好文 > 详细

remove-duplicates-from-sorted-list

时间:2016-10-26 20:06:21      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:class   head   move   while   from   node   let   list   dup   

https://leetcode.com/problems/remove-duplicates-from-sorted-list/

 

    public ListNode deleteDuplicates(ListNode head) {
        int last = -1;
        ListNode store = null;
        ListNode cur = head;
        while (cur != null) {
            if (store == null) {
                store = head;
            }
            else if (cur.val != last) {
                store = store.next;
                store.val = cur.val;
            }
            last = cur.val;
            cur = cur.next;
        }
        if (store != null) {
            store.next = null;
        }
        return head;
    }

 

remove-duplicates-from-sorted-list

标签:class   head   move   while   from   node   let   list   dup   

原文地址:http://www.cnblogs.com/charlesblc/p/6001379.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!