【Leetcode】404. Sum of Left Leaves
404. Sum of Left Leaves
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution
{
public:
int sumOfLeftLeaves(TreeNode* root)
{
int res = ;
solute(root, res, false);
return res;
} void solute(TreeNode *root, int &sum, bool flag)
{
if(root == nullptr)
return;
if(!root->left && !root->right)
{
if(flag == true)
sum += root->val;
return;
}
solute(root->left, sum, true);
solute(root->right, sum, false);
return;
}
};
【Leetcode】404. Sum of Left Leaves的更多相关文章
- 【LeetCode】404. Sum of Left Leaves 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目大意 题目大意 解题方法 递归 迭代 日期 [LeetCode] 题目地址:h ...
- 【easy】404. Sum of Left Leaves
求所有左节点的和. /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; ...
- 【LeetCode】129. Sum Root to Leaf Numbers 解题报告(Python)
[LeetCode]129. Sum Root to Leaf Numbers 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/pr ...
- 【leetcode】907. Sum of Subarray Minimums
题目如下: 解题思路:我的想法对于数组中任意一个元素,找出其左右两边最近的小于自己的元素.例如[1,3,2,4,5,1],元素2左边比自己小的元素是1,那么大于自己的区间就是[3],右边的区间就是[4 ...
- 【LeetCode】633. Sum of Square Numbers
Difficulty: Easy More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/sum-of-square-n ...
- 【LeetCode】Two Sum II - Input array is sorted
[Description] Given an array of integers that is already sorted in ascending order, find two numbers ...
- 【leetcode】Path Sum IV
If the depth of a tree is smaller than 5, then this tree can be represented by a list of three-digit ...
- 【LeetCode】1022. Sum of Root To Leaf Binary Numbers 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS 日期 题目地址:https://leetco ...
- 【LeetCode】Path Sum(路径总和)
这道题是LeetCode里的第112道题.是我在学数据结构——二叉树的时候碰见的题.题目要求: 给定一个二叉树和一个目标和,判断该树中是否存在根节点到叶子节点的路径,这条路径上所有节点值相加等于目标和 ...
随机推荐
- Linux记录-集群时间同步解决方案
1.各个主机安装ntpdate 2.编写shell #!/bin/sh array=("root@master" "root@slave002" "r ...
- C# Dictionary序列化/反序列化
[Serializable] public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue& ...
- Java中BIO、NIO、AIO的区别和应用场景
学习IO,首先要明白四个东西. 1.同步 java自己去处理io. 2.异步 java将io交给操作系统去处理,告诉缓存区大小,处理完成回调. 3.阻塞 ...
- MyBatis全局配置文件MyBatis-config.xml代码
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC ...
- # 20155214 2016-2017-2 《Java程序设计》第8周学习总结
20155214 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 对于串流输入/输出使用inputStream/OutputStream来衔接数据源与目的地, ...
- sql server存储过程简单的使用
--创建存储过程 create proc test_proc @date datetime as select * from t_user where times between ),),),),' ...
- JavaScript之Dom1|DOM2|DOM3之DOM1【节点层次】
长文慎读. 导航: 1.节点层次 2.Node类型 3.Document类型 4.Element类型 5.Text类型 6.Comment类型 7.CDATASection类型 8.DocumentT ...
- [C++]指针与引用(应用辨析)
1.指针变量允许将一个整数经强制转换后赋值给指针变量 Eg: float *fp; fp = (float *)5000;//意义:将5000作为一个地址赋给指针变量fp 2 ...
- python时间序列画图plot总结
画图从直觉上来讲就是为了更加清晰的展示时序数据所呈现的规律(包括趋势,随时间变化的规律(一周.一个月.一年等等)和周期性规律),对于进一步选择时序分析模型至关重要.下面主要是基于pandas库总结一下 ...
- MHA-Failover可能遇到的坑
一.主从数据一致性 1.1.如何保证主从数据一致性 参考叶师傅文章:FAQ系列 | 如何保证主从复制数据一致性 在MySQL中,一次事务提交后,需要写undo.写redo.写binlog,写数据文件等 ...