Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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;
    }
};
posted on 2014-07-18 01:01  Tonix  阅读(129)  评论(0)    收藏  举报