import java.util.*;
public class Solution {
public TreeNode pruneLeaves (TreeNode root) {
// 预处理
if (root == null) return null;
// 判断左结点是否为叶子结点
if (root.left != null && isLeaf(root.left)) return null;
// 判断右结点是否为叶子结点
if (root.right != null && isLeaf(root.right)) return null;
// 递归修剪左右子树
root.left = pruneLeaves(root.left);
root.right = pruneLeaves(root.right);
// 返回修剪后的树
return root;
}
// 判读当前结点是否为叶子节点
public static boolean isLeaf(TreeNode node) {
// 预处理
if (node == null) return false;
// 当前结点没有子结点则为叶子结点
return node.left == null && node.right == null;
}
}