Delete Nodes in a List
Remove every node whose value appears anywhere in the Python list nums, and return the head. The other nodes keep their order. The list is passed in as head.
Linked lists appear in the tests as the list of their values, like [1,2,3]. Each node is a ListNode with .val and .next; the class is already defined for you.
Example 1
head [1,2,3,4,5]
nums [1,4]
returns [2,3,5]
The 1 and the 4 are removed.
Example 2
head [2,2]
nums [2]
returns []
Everything is removed.
Constraints
0 <= number of nodes <= 1000 <= len(nums) <= 20-100 <= Node.val, nums[i] <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.