/**
* 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) {
ListNode *q=head,*p=head;
while(p->next!=NULL)
{
q=p;
p=p->next;
if(p->val==val)
{
q->next=p->next;
}
}
return head;
}
};