/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* removeElements(ListNode* head, int val) {
if (head == NULL)
{
return NULL;
}
ListNode* p = new ListNode(0);
p->next = head;
ListNode* pre = p;
while (pre->next)
{
if (pre->next->val == val)
{
pre->next = pre->next->next;
}
else
pre = pre->next;
}
return p->next;
}
};