image_2022-04-01_15-06-04.png
36.4 KB
#N404. Sum of Left Leaves
problem link
#solution
problem link
#solution
class Solution {
public int sumOfLeftLeaves(TreeNode root) {
int res=0;
if(root == null) return 0;
if(root.left != null){
if(root.left.left == null && root.left.right == null) res += root.left.val;
else res += sumOfLeftLeaves(root.left);
}
res+=sumOfLeftLeaves(root.right);
return res;
}
}