root of a binary tree and a number mark. Remove every leaf whose value equals mark.
Once a leaf is removed, its parent may become a leaf itself. If that parent also holds mark, remove it as well, and keep going until no leaf with the value mark is left.
Return the root of the resulting tree, or an empty tree if everything was removed.root=tree_node([4, 7, 9, 7, None, 7, 7]), mark=7 → [4, None, 9]
First the three leaves holding 7 are cut. Then the root's left child, also 7, becomes a leaf and goes too. Node 9 is now childless, but its value is not 7, so it stays.
root=tree_node([5, 5, None, 5]), mark=5 → None
The chain of 5s is cut from the bottom up, root included, leaving an empty tree.
root=tree_node([3, 8, 2, None, 6]), mark=8 → [3, 8, 2, None, 6]
Node 8 is not a leaf since it has the child 6, so nothing is removed.
root=tree_node([4, 7, 9, 7, None, 7, 7]), mark=7
[4, None, 9]
Run checks the first 3 tests in your browser. Submit checks all 32 tests on the server, hidden ones included.