http://oj.leetcode.com/problems/remove-duplicates-from-sorted-list/
链表去重。需要考虑的特殊情况是: 输入为空链表,应该如何处理?
所以要用 while(head != NULL) 而不是 while(1)
/**
* 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) {
ListNode *start = head;
while(head != NULL) {
if(head->next == NULL) break;
if(head->val == head->next->val) {
head->next = head->next->next;
} else {
head = head->next;
}
}
return start;
}
};