class Solution {
public int sumOfLeftLeaves(TreeNode root) {
if(root == null){
return 0;
}
int sumleft = sumOfLeftLeaves(root.left);
int sumRight = sumOfLeftLeaves(root.right);
int midValue = 0;
if(root.left != null && root.left.left == null && root.left.right == null){
midValue = root.left.val;
}
int sum = midValue + sumleft + sumRight;
return sum;
}
}
代码随想录算法训练营第十七天 404.左叶子之和
最新推荐文章于 2024-05-24 19:42:33 发布