import java.util.*;
public class Solution {
public int sumOfLeftLeaves (TreeNode root) {
// 预处理
if (root == null) return 0;
// 判断当前左子树是否为叶子结点
if (root.left != null && isLeaf(root.left)) {
return root.left.val + sumOfLeftLeaves(root.right);
}
// 若不是,则递归求左右子树的左叶子之和
return sumOfLeftLeaves(root.left) + sumOfLeftLeaves(root.right);
}
// 判断当前结点是否为叶子结点
public static boolean isLeaf(TreeNode node) {
// 预处理
if (node == null) return false;
// 没有后继的结点即为叶子结点
return node.left == null && node.right == null;
}
}