Delete Leaves With a Given Value LeetCode solution in Java
1class Solution {2public TreeNode removeLeafNodes(TreeNode root, int target) {3if (root == null) return root;4root.left = removeLeafNodes(root.left, target);5root.right = removeLeafNodes(root.right, target);6if (root.left == null && root.right == null && root.val == target) root = null;7return root;8}9}