链表问题如果没编过,查代码一定有哪里出现指针飞了,这个地方是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;
}
};