Given a binary tree and a number target, remove all leaf nodes that have the value equal to target.
After removing a leaf, if its parent becomes a leaf and has value target, remove it too. Continue this until no more nodes can be deleted.
Input: root = [5,3,6,3,null,6,7], target = 3
Output: [5,null,6,null,7]
Explanation:
Leaf nodes with value 3 are removed. Then the parent node becomes a leaf with value 3, so it is removed as well.
Input: root = [4,2,2,2,5], target = 2
Output: [4,2,null,null,5]
Input: root = [1,2,null,2,null,2], target = 2
Output: [1]
Explanation:
All leaf nodes with value 2 are removed recursively.
Accepted:
Submission: