[leetcode] Remove Linked List Elements
[leetcode] Remove Linked List Elements
class Solution {
public:
ListNode* removeElements(ListNode* head, int val) {
ListNode *cur = head;
if(!head) return head;
while(cur->next) {
if(cur->next->val == val) cur->next = cur->next->next;
else cur = cur->next;
}
if(head->val == val) head = head->next;
return head;
}
};