-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path814.java
More file actions
31 lines (31 loc) · 1.09 KB
/
814.java
File metadata and controls
31 lines (31 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
__________________________________________________________________________________________________
0ms
class Solution {
public TreeNode pruneTree(TreeNode root) {
if(root==null) return null;
if( pruneTree(root.left)==null) root.left=null;
if( pruneTree(root.right)==null) root.right=null;
return (root.right==null && root.left==null && root.val==0) ? null : root;
}
}
__________________________________________________________________________________________________
sample 35584 kb submission
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public TreeNode pruneTree(TreeNode root) {
if (root == null) return null;
root.left = pruneTree(root.left);
root.right = pruneTree(root.right);
if (root.val == 0 && root.left == null && root.right == null) return null;
return root;
}
}
__________________________________________________________________________________________________