Back to problems

Remove all occurrences of a target value from a linked list

Algorithm · Arista · Easy

You are provided with the head node of a singly linked list and a value target. Delete every node whose .val equals target. Afterwards, return the head of the modified list. If all nodes contain the target value, return an empty list (conventionally null or printed as a blank line). The original ordering of the remaining nodes must be preserved. Example 1: Explanation: The nodes with value 9 are removed, leaving the sequence 2 → 15. Example 2: Example 3: Explanation: Every…

Loading the rest of the question…