Problem statement

https://binarysearch.com/problems/Linked-List-Deletion/

Solution

Equal to Leetcode 0203. Remove Linked List Elements.

Complexity

It is O(n) for time and O(1) for space.

Code

class Solution:
    def solve(self, head, target):
        dummy = LLNode(-1)
        dummy.next = head
        start = dummy
        while start.next:
            if start.next.val == target:
                start.next = start.next.next
            else:
                start = start.next         
        return dummy.next