Back to course home
0% completed
Solution: Delete Leaves With a Given Value
Problem Statement
Given a root
node of a binary tree and an integer target
, delete all leaf nodes that have a value equal to target
.
After removing such leaf nodes, if any of their parent nodes become leaf nodes with a value equal to target
, they should also be removed. This process should continue until no more nodes can be deleted.
Examples
Example 1
- Input: root =
[1, 5, 3, 5, null, 5, 4]
, Target:5
- Expected Output:
[1,null,3,null,4]
- Explanation: The left child of
5
(left of root) is3
and5
- Explanation: The left child of
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible