Skip to content

Commit 0d5a21b

Browse files
add skeleton for 1325
1 parent 3287ff8 commit 0d5a21b

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.fishercoder.solutions;
2+
3+
import com.fishercoder.common.classes.TreeNode;
4+
5+
/**
6+
* 1325. Delete Leaves With a Given Value
7+
*
8+
* Given a binary tree root and an integer target, delete all the leaf nodes with value target.
9+
* Note that once you delete a leaf node with value target, if it's parent node becomes a leaf node and has the value target,
10+
* it should also be deleted (you need to continue doing that until you can't).
11+
*
12+
* Example 1:
13+
* 1 1 1
14+
* / \ / \ \
15+
* 2 3 -> 2 3 -> 3
16+
* / / \ \ \
17+
* 2 2 4 4 4
18+
*
19+
* Input: root = [1,2,3,2,null,2,4], target = 2
20+
* Output: [1,null,3,null,4]
21+
* Explanation: Leaf nodes in green with value (target = 2) are removed (Picture in left).
22+
* After removing, new nodes become leaf nodes with value (target = 2) (Picture in center).
23+
*
24+
* Example 2:
25+
* 1 1
26+
* / \ /
27+
* 3 3 -> 3
28+
* / \ \
29+
* 3 2 2
30+
*
31+
* Input: root = [1,3,3,3,2], target = 3
32+
* Output: [1,3,null,null,2]
33+
*
34+
* Example 3:
35+
* 1 1 1 1
36+
* / / /
37+
* 2 2 2
38+
* / -> / -> ->
39+
* 2 2
40+
* /
41+
* 2
42+
*
43+
* Input: root = [1,2,null,2,null,2], target = 2
44+
* Output: [1]
45+
* Explanation: Leaf nodes in green with value (target = 2) are removed at each step.
46+
*
47+
* Example 4:
48+
* 1
49+
* / \ ->
50+
* 1 1
51+
* Input: root = [1,1,1], target = 1
52+
* Output: []
53+
*
54+
* Example 5:
55+
* 1 1
56+
* / \ -> / \
57+
* 2 3 2 3
58+
*
59+
* Input: root = [1,2,3], target = 1
60+
* Output: [1,2,3]
61+
*
62+
* Constraints:
63+
* 1 <= target <= 1000
64+
* Each tree has at most 3000 nodes.
65+
* Each node's value is between [1, 1000].
66+
* */
67+
public class _1325 {
68+
public static class Solution1 {
69+
public TreeNode removeLeafNodes(TreeNode root, int target) {
70+
return null;
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)