83. Remove Duplicates from Sorted List

问题描述

解决方案

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        if(!head||!head->next) return head; 
        ListNode* node =head;
        while(head!=NULL)
        {
            while(head->next!=NULL&&head->val==head->next->val)
            {
                head->next=head->next->next; 
            }
            head=head->next;
        }
        return node ;
    }
};
posted @ 2016-08-26 13:25  弦断  阅读(163)  评论(0编辑  收藏  举报