鏈表問題如果沒編過,查代碼一定有哪裏出現指針飛了,這個地方是null然而還操作......
/**
* 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 *re=head;
while(re)
{
while(re->next&&re->val==re->next->val)
{
re->next=re->next->next;
}
re=re->next;
}
return head;
}
};