<reponame>anishLearnsToCode/leetcode-algorithms
from typing import Union


# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next


class Solution:
    def removeElements(self, head: ListNode, val: int) -> Union[None, ListNode]:
        current = ListNode(val=0, next=head)
        start = current
        while current is not None and current.next is not None:
            if current.next.val == val:
                current.next = current.next.next
            else:
                current = current.next
        return start.next
