1class Solution {2public ListNode removeElements(ListNode head, int val) {3if (head == null) {4return head;5}6ListNode result = head;7while (head.next != null) {8if (head.next.val == val) {9head.next = head.next.next;10} else {11head = head.next;12}13}14if (result.val == val) {15result = result.next;16}17return result;18}19}