public class RemoveElements {
	public static void main(String[] args) {
		ListNode head = new ListNode(1, null);
		System.out.println(removeElements(head, 2));
	}
   public static ListNode removeElements(ListNode head, int val) {
        if (head == null) return null;
		ListNode fake = new ListNode(0);
		fake.next = head;
		ListNode fast = head;
		ListNode slow = fake;
		while (fast != null) {
			if (fast.val == val) {
				fast = fast.next;
				slow.next = fast;		
			} else {
				fast = fast.next;
				slow = slow.next;
			}
		}
		return fake.next;
    }
}
