A notification center keeps its toast messages in a linked list. Each node's val is the id of the toast's type. When the user clicks "dismiss all" on one type, every toast of that type must go.
Write dropToasts(head, type) that removes every node whose val equals type and returns the head of the list that is left. Keep the other nodes in their original order. If every node is removed, return null.
Input: head = [1,2,6,3,4,5,6], type = 6 Output: [1,2,3,4,5]
Both nodes holding 6 are removed; the rest keep their order.
Input: head = [7,7,7,7], type = 7 Output: []
Every toast is of type 7, so nothing is left.
0 to 10^4 nodes.1 <= node.val, type <= 50Lists are written as arrays here, like [1, 2, 3]. Your function works with ListNode objects, each with val and next.
Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #224 Drop Dismissed Toasts. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.