You are given the head of a singly linked list and an integer target.
Remove all nodes whose value equals target, and return the (possibly new) head of the list.
head
: head node of a singly linked list (may be
null
)
target
: integer
0 <= n <= 10^5
target
fit in 32-bit signed integer
O(n)
time and
O(1)
extra space (not counting the list itself)
1 -> 2 -> 6 -> 3 -> 4 -> 5 -> 6
,
target = 6
⇒
1 -> 2 -> 3 -> 4 -> 5
7 -> 7 -> 7
,
target = 7
⇒
(empty list)
target = 1
⇒
(empty list)