/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode removeElements(ListNode head, int val) {
ListNode myHead = new ListNode(0);
myHead.next = head;
ListNode pre = myHead;
while (pre.next != null) {
if (pre.next.val == val) pre.next = pre.next.next;
else pre = pre.next;
}
return myHead.next;
}
}