思路: 遍历树,如果碰到左叶子节点加进来
class Solution {
private int add = 0;
public int sumOfLeftLeaves(TreeNode root) {
if(root == null) return 0;
F(root);
return add;
}
public void F(TreeNode root)
{
if(root != null)
{
if(root.left != null && root.left.left == null && root.left.right == null) add += root.left.val;
F(root.left);
F(root.right);
}
}
}