Class Solution
java.lang.Object
g1301_1400.s1325_delete_leaves_with_a_given_value.Solution
1325 - Delete Leaves With a Given Value.<p>Medium</p>
<p>Given a binary tree <code>root</code> and an integer <code>target</code>, delete all the <strong>leaf nodes</strong> with value <code>target</code>.</p>
<p>Note that once you delete a leaf node with value <code>target</code> ** , ** if its parent node becomes a leaf node and has the value <code>target</code>, it should also be deleted (you need to continue doing that until you cannot).</p>
<p><strong>Example 1:</strong></p>
<p><strong><img src="https://assets.leetcode.com/uploads/2020/01/09/sample_1_1684.png" alt="" /></strong></p>
<p><strong>Input:</strong> root = [1,2,3,2,null,2,4], target = 2</p>
<p><strong>Output:</strong> [1,null,3,null,4]</p>
<p><strong>Explanation:</strong> Leaf nodes in green with value (target = 2) are removed (Picture in left). After removing, new nodes become leaf nodes with value (target = 2) (Picture in center).</p>
<p><strong>Example 2:</strong></p>
<p><strong><img src="https://assets.leetcode.com/uploads/2020/01/09/sample_2_1684.png" alt="" /></strong></p>
<p><strong>Input:</strong> root = [1,3,3,3,2], target = 3</p>
<p><strong>Output:</strong> [1,3,null,null,2]</p>
<p><strong>Example 3:</strong></p>
<p><strong><img src="https://assets.leetcode.com/uploads/2020/01/15/sample_3_1684.png" alt="" /></strong></p>
<p><strong>Input:</strong> root = [1,2,null,2,null,2], target = 2</p>
<p><strong>Output:</strong> [1]</p>
<p><strong>Explanation:</strong> Leaf nodes in green with value (target = 2) are removed at each step.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li>The number of nodes in the tree is in the range <code>[1, 3000]</code>.</li>
<li><code>1 <= Node.val, target <= 1000</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
removeLeafNodes
-