/**
* 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 == nullptr)
return nullptr;
while(head->val == val){
head = head->next;
if(head == nullptr)
return nullptr;
}
ListNode* go = head->next;
ListNode* go_s = head;
while(go != nullptr){
if(go->val == val){
go_s->next = go->next;
go = go->next;
continue;
}
go = go->next;
go_s = go_s->next;
}
return head;
}
};