We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent afe97b6 commit 9a972b9Copy full SHA for 9a972b9
BinaryTreePruning.java
@@ -0,0 +1,29 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * public class TreeNode {
4
+ * int val;
5
+ * TreeNode left;
6
+ * TreeNode right;
7
+ * TreeNode() {}
8
+ * TreeNode(int val) { this.val = val; }
9
+ * TreeNode(int val, TreeNode left, TreeNode right) {
10
+ * this.val = val;
11
+ * this.left = left;
12
+ * this.right = right;
13
+ * }
14
15
+ */
16
+class Solution {
17
+ public TreeNode pruneTree(TreeNode root) {
18
+
19
+ if (root == null) return null;
20
21
+ root.left = pruneTree(root.left);
22
+ root.right = pruneTree(root.right);
23
24
+ if (root.left == null && root.right == null && root.val == 0) return null;
25
26
+ return root;
27
28
+ }
29
+}
0 commit comments