Skip to content
BytePatterns

Remove Value Nodes

EasyLinked Lists#dummy-node#pointer-relinking~15m

Problem

Given the head of a singly linked list and a target value, remove every node holding that value and return the head of what remains. Nodes are unlinked rather than copied into a new list, and the surviving nodes keep their original order. The result may be empty.

Examples

Input:  head = 1 -> 2 -> 6 -> 3 -> 6, target = 6
Output: 1 -> 2 -> 3
Input:  head = 7 -> 7 -> 7, target = 7
Output: empty
Why:    edge case, every node matches and the list empties out
Input:  head = empty, target = 1
Output: empty
Why:    edge case, there is nothing to remove

Hints

0 / 3

Stuck on the idea rather than the code? Insert and Delete covers it.