dsa · easy
Strip Linked List Values
You are given head, the node values of a singly linked list, and an integer val. Delete every node whose value equals val. Return the remaining values in their original order.
Arguments
head— node values of the list, front to back;[]if emptyval— value to strip out of the list
If every node is removed, return an empty list.
Example
head = [7,7,3,7,1], val = 7
Drop the three 7s. 3 and 1 stay, in that order → [3,1].
[2,2], val = 2 → [].
Constraints
0 <= head.length <= 4*10^4 1 <= head[i], val <= 50 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [7,7,3,7,1] 7 Expected: [3,1]
Example 2
Input: [2,2] 2 Expected: []
Example 3
Input: [1,2,3] 4 Expected: [1,2,3]