Remove Linked List Elements
Given the head of a linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and return the new head.
Example 1
[1] -> [2] -> [6] -> [3] -> [4] -> [5] -> [6] -> null --- [1] -> [2] -> [3] -> [4] -> [5] -> null
Input
head = [1,2,6,3,4,5,6], val = 6Output
[1,2,3,4,5]All nodes with value 6 are removed, leaving the remaining nodes in their original order.
Example 2
null --- null
Input
head = [], val = 1Output
[]The list is empty, so there are no nodes to remove.
Constraints
- The number of nodes in the list is in the range
[0, 10^4]. 1 <= Node.val <= 500 <= val <= 50