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

LeetCode "Remove Duplicates from Sorted List"

时间:2014-07-18 14:36:54      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   re   c   

The key of this problem is about details especially boundary conditions.

class Solution {
public:
    ListNode *deleteDuplicates(ListNode *head) {
        if(!head) return NULL;

        ListNode *p  = head;
        ListNode *p0 = p->next;
        while(p && p0)   
        {
            while(p && p0 && p->val == p0->val)
            {
                p->next = p0->next;
                p0 = p0->next;
            }

            p = p0;
            if(p0) p0 = p0->next;
        }

        return head;
    }
};

LeetCode "Remove Duplicates from Sorted List",布布扣,bubuko.com

LeetCode "Remove Duplicates from Sorted List"

标签:style   blog   color   io   re   c   

原文地址:http://www.cnblogs.com/tonix/p/3852509.html

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