364. Remove Linked List Elements by Value

MediumLinked ListLinked List

Given the head of a linked list and an integer val, remove all nodes whose value equals val and return the new head. The list is given as an array; return the resulting array. Input: '[list], val'.

Input: '[list], val'.

Output: Array — the list after removals.

Examples

Example 1
Input: [1,2,6,3,4,5,6], 6
Output: [1,2,3,4,5]
Explanation: Both 6s removed.
Example 2
Input: [7,7,7,7], 7
Output: []
Explanation: All removed.
Example 3
Input: [1,2,3], 4
Output: [1,2,3]
Explanation: No match.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →