Leetcode-标签为Tree 404. Sum of Left Leaves
来源:互联网 发布:安卓6.0优化教程 编辑:程序博客网 时间:2024/06/08 12:04
原题
Find the sum of all left leaves in a given binary tree.
Example:
3 / \ 9 20 / \ 15 7
There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.
代码实现
public class LeftLeafSum { public int SumOfLeftLeaves(TreeNode root) { if (root == null) return 0; int sum=0; if (root.left!=null && isLeaf(root.left))//左叶子 sum += root.left.val; sum += SumOfLeftLeaves(root.left); sum += SumOfLeftLeaves(root.right); return sum; } private bool isLeaf(TreeNode node) { return node.left == null && node.right == null; } }
2 0
- Leetcode-标签为Tree 404. Sum of Left Leaves
- LeetCode笔记:404. Sum of Left Leaves
- 【leetcode】404. Sum of Left Leaves【E】
- LeetCode—404. Sum of Left Leaves
- [LeetCode]404. Sum of Left Leaves
- Leetcode 404. Sum of Left Leaves
- LeetCode 404. Sum of Left Leaves
- 404. Sum of Left Leaves - leetcode
- [LeetCode]--404. Sum of Left Leaves
- LeetCode 404. Sum of Left Leaves
- [leetcode]404. Sum of Left Leaves
- LeetCode-404. Sum of Left Leaves
- LeetCode 404. Sum of Left Leaves
- LeetCode 404. Sum of Left Leaves
- leetcode 404. Sum of Left Leaves
- leetcode(88).404. Sum of Left Leaves
- 【LeetCode】 404. Sum of Left Leaves
- leetcode 404. Sum of Left Leaves
- 泛型概述
- 泛型的概述
- 数据库
- 构造函数 及复制构造函数
- ZOJ3962 数位DP
- Leetcode-标签为Tree 404. Sum of Left Leaves
- 《C++之那些年踩过的坑(二)》
- unity联网模块制作
- 《深入理解Java虚拟机》Java内存区域与内存溢出异常
- 项目零散知识积累(三)
- Ubuntu下使用VI编辑文件必知的常用命令
- 欢迎使用CSDN-markdown编辑器
- JS浅克隆与深克隆
- [Cocos2D]Cocos2D在Windows上面的环境搭建