class Solution:
def removeElements(self, head: ListNode, val: int) -> ListNode:
temp=ListNode(0)
temp.next=head
pre, cur=temp, head
while cur:
if cur.val==val:
pre.next=cur.next;
else:
pre=cur
cur=cur.next
return temp.next
class Solution {
public:
ListNode* removeElements(ListNode* head, int val) {
ListNode* dummyhead=new ListNode(0);
dummyhead->next=head;
ListNode* cur=dummyhead;
while(cur->next!=nullptr){
if(cur->next->val==val){
ListNode* temp=cur->next;
cur->next = cur->next->next;
}
else{
cur=cur->next;
}
}
return dummyhead->next;
}
};