``
ListNode dummyHead = new ListNode(-1);
dummyHead.next = head;
ListNode prev = dummyHead;
while(prev.next != null){
if(prev.next.val == val){
ListNode delNode = prev.next;
prev = prev.next.next;
delNode.next = null;
}else{
prev = prev.next;
}
}
return dummyHead.next;
}
``