Problem
You get the head of a linked list and a number val. Remove every node whose value equals `val` and return the head of what is left. The head itself may need to go, possibly several times in a row.
Example 1
- Input
- 1
- Output
- 2 -> 6 -> 3 -> 4 -> 5 -> 6, val = 6 → 1 -> 2 -> 3 -> 4 -> 5
Example 2
- Input
- 7
- Output
- 7 -> 7 -> 7, val = 7 →
- Why
- empty
Example 3
- Input
- (empty), val = 1
- Output
- (empty)
Return None (null in TypeScript) for an empty result.
Constraints
0 <= number of nodes <= 10^41 <= Node.val <= 500 <= val <= 50