Binary Tree Pruning LeetCode solution in Java

1
class Solution {
2
public TreeNode pruneTree(TreeNode root) {
3

4
if (root == null) return root;
5

6
root.left = pruneTree(root.left);
7
root.right = pruneTree(root.right);
8

9
if (root.left == null && root.right == null && root.val == 0) return null;
10
else return root;
11
}
12
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0