leetcode 404 Sum of Left Leaves
来源:互联网 发布:成都闪电seo 编辑:程序博客网 时间:2024/06/10 02:17
Problem:
给一颗二叉树,求这棵树的左叶子节点之和。
Solution:
dfs搜一下即可。
notes:
1. 默认参数的应用。
2. 要注意root可能为空,如果为空则不能方位它的左值,所以要处理这个异常。
class Solution {public: int sumOfLeftLeaves(TreeNode* root, bool isLeft = false) { int ans = 0; if(!root) return 0; if(isLeft && !root->left && !root->right) ans += root->val; else { ans += sumOfLeftLeaves(root->left, true); ans += sumOfLeftLeaves(root->right); } return ans; }};
1 0
- LeetCode 404 Sum of Left Leaves
- [LeetCode-404]Sum of Left Leaves(java)
- Leetcode 404 Sum of Left Leaves
- LeetCode[404] Sum of Left Leaves
- LeetCode #404: Sum of Left Leaves
- LeetCode 404 Sum of Left Leaves (DFS)
- leetcode 404 Sum of Left Leaves
- LeetCode #404 - Sum of Left Leaves - Easy
- leetcode 404 Sum of Left Leaves C++
- 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
- Sum of Left Leaves ---LeetCode
- Leetcode Sum of Left Leaves
- LEETCODE--Sum of Left Leaves
- CentOS安装nexus(Maven仓库管理器)
- java中最常用jar包的用途说明
- 搭建ElasticSearch 5.2 Java API开发环境
- Java正确URL解码方式:URLDecoder.decode
- Mac下使用brew安装mongodb
- leetcode 404 Sum of Left Leaves
- OIV用户手册
- 利用JDK8的新特性计算某个目录下的文件中包含字符串的次数
- Runtime.availableProcessors()
- HTML5 drag drop
- 阿里云安装redis
- Ngxin安装、反向代理、负载均衡学习笔记
- JVM 基础概念
- 数字的人民币中文读法