404. Sum of Left Leaves
来源:互联网 发布:51单片机课程设计课题 编辑:程序博客网 时间:2024/05/22 15:42
没有什么好说的,求二叉树所有左叶子节点的值
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public int sumOfLeftLeaves(TreeNode root) {
if (root == null)
return 0;
int sum = 0;
if (root.left != null && root.left.left == null && root.left.right == null) {
sum += root.left.val;
} else {
sum += sumOfLeftLeaves(root.left);
}
sum += sumOfLeftLeaves(root.right);
return sum;
}
}
0 0
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves*
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- myeclipse编写的html页面乱码问题
- listview数据显示在最底部的设置
- C#定时检查子线程是否执行完成(定时器检查)
- spark算子cogroup讲解
- Linux信号详解
- 404. Sum of Left Leaves
- 测试要求和指标
- TensorFlow入门-MNIST & softmax regression
- 数据库事务隔离级别
- Datatables v1.10服务端模式启动js-java版本
- 完美解决频繁跳槽者的两大求职难题
- 机器学习和统计里面的auc怎么理解?
- 用户登录网站
- ios UITextField 添加内边距 或者修改文字位置