Delete Leaves With a Given Value LeetCode solution in Java

1
class Solution {
2
public TreeNode removeLeafNodes(TreeNode root, int target) {
3
if (root == null) return root;
4
root.left = removeLeafNodes(root.left, target);
5
root.right = removeLeafNodes(root.right, target);
6
if (root.left == null && root.right == null && root.val == target) root = null;
7
return root;
8
}
9
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0