[LeetCode] Remove Duplicates from Sorted List

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

这是大学生作业么... 

 1 class Solution {
 2 public:
 3     ListNode *deleteDuplicates(ListNode *head) {
 4         // IMPORTANT: Please reset any member data you declared, as
 5         // the same Solution instance will be reused for each test case.
 6         if (head == NULL) return NULL;
 7         ListNode* pre = head;
 8         ListNode* cur = head->next;
 9         while(cur) {
10             if (pre->val == cur->val) {
11                 ListNode* p = cur;
12                 pre->next = cur->next;
13                 cur = pre->next;
14                 delete(p);
15                 p = NULL;
16             } else {
17                 pre = cur;
18                 cur = cur->next;
19             }
20         }
21         return head;
22     }
23 };

 

posted @ 2013-11-18 21:36  NextLife  阅读(194)  评论(0)    收藏  举报