/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
private int result;
public int sumOfLeftLeaves(TreeNode root) {
if(root==null){
return 0;
}
if(root.left!=null){
//只在属于左子树的递归中计算结果
sumOfLeftLeaves(root.left);
if(root.left.left==null && root.left.right==null){
result+=root.left.val;
}
}
sumOfLeftLeaves(root.right);
return result;
}
}