class Solution {
int sum;
public int sumOfLeftLeaves(TreeNode root) {
if(root==null)return 0;
solve(root,false);
return sum;
}
public void solve(TreeNode root, boolean flag){
if(root==null) return;
if(root.left==null&&root.right==null&flag)
sum+=root.val;
else{
solve(root.left,true);
solve(root.right,false);
}
}
}
又写出一个递归题目(← ←)