Remove all elements from a linked list of integers that have value val.
Example:
Input: 1->2->6->3->4->5->6, val = 6 Output: 1->2->3->4->5
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* removeElements(struct ListNode* head, int val){
struct ListNode* prev = NULL;
struct ListNode* curr = head;
while (curr != NULL) {
if (curr->val == val) {
if (prev != NULL) {
curr = curr->next;
prev->next = curr;
continue;
}
else {
head = curr->next;
curr = head;
continue;
}
}
prev = curr;
curr = curr->next;
}
return head;
}