You're given an array of integers nums containing values that need to be filtered out from a linked list. Your task is to traverse the linked list and remove all nodes whose values appear anywhere in the nums array.
Think of it as having a blacklist of values - any node in the linked list matching a value from this blacklist should be deleted. The challenge is to do this efficiently while maintaining the structure of the remaining linked list.
Goal: Return the head of the modified linked list after removing all blacklisted nodes.
Input: An array nums and the head of a singly linked list
Output: The head of the filtered linked list
Input & Output
Constraints
- 1 โค nums.length โค 105
- 1 โค nums[i] โค 105
- The number of nodes in the given list is in the range [1, 105]
- 1 โค Node.val โค 105
- The input is generated such that there is at least one node in the linked list that has a value not present in nums