1325. Delete Leaves With a Given Value

Practice Delete Leaves With a Given Value for free on NudgeCode: Medium, Binary Tree pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Remove every leaf whose value is target. If removing a leaf turns its parent into a leaf with value target, remove the parent too, and keep going until no such leaf is left. Return the root (or an empty tree).

Example

root = [1,2,3,2,null,2,4], target = 2  ->  [1,null,3,null,4]

Constraints