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的更多相关文章

  1. 【LeetCode】404. Sum of Left Leaves 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目大意 题目大意 解题方法 递归 迭代 日期 [LeetCode] 题目地址:h ...

  2. 【easy】404. Sum of Left Leaves

    求所有左节点的和. /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; ...

  3. 【LeetCode】129. Sum Root to Leaf Numbers 解题报告(Python)

    [LeetCode]129. Sum Root to Leaf Numbers 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/pr ...

  4. 【leetcode】907. Sum of Subarray Minimums

    题目如下: 解题思路:我的想法对于数组中任意一个元素,找出其左右两边最近的小于自己的元素.例如[1,3,2,4,5,1],元素2左边比自己小的元素是1,那么大于自己的区间就是[3],右边的区间就是[4 ...

  5. 【LeetCode】633. Sum of Square Numbers

    Difficulty: Easy  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/sum-of-square-n ...

  6. 【LeetCode】Two Sum II - Input array is sorted

    [Description] Given an array of integers that is already sorted in ascending order, find two numbers ...

  7. 【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 ...

  8. 【LeetCode】1022. Sum of Root To Leaf Binary Numbers 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS 日期 题目地址:https://leetco ...

  9. 【LeetCode】Path Sum(路径总和)

    这道题是LeetCode里的第112道题.是我在学数据结构——二叉树的时候碰见的题.题目要求: 给定一个二叉树和一个目标和,判断该树中是否存在根节点到叶子节点的路径,这条路径上所有节点值相加等于目标和 ...

随机推荐

  1. 查看windows下指定的端口是否开放

    有时候会出现ip  ping的通   但是就是连接不上的情况.这时候我们需要检测一下这个端口是否被开放 netstat -ano -p tcp | find >nul && ec ...

  2. JS文本框获取焦点

    所谓焦点,就是鼠标移上文本框的时候那个一闪一闪的光标.

  3. UVALive - 7263 Today Is a Rainy Day(bfs)

    原题链接 题意 给两个等长的只含数字1,2,3,4,5,6的字符串s(|s|≤110),有两种操作: - 把一个位置的数字换成另一个数字,换成的数字也只能是1到6- 把这个字符串中相同的数字都换成另一 ...

  4. 两年.net码农总结

    一直都是在博客园看文章,几乎每个两三天都会来,不管是看技术分享还是看经验总结,我觉得这真是个好地方. 工作两年,24.5岁,目前达到8.5K(即10W)的.net web. 文章水平不好,各位见谅了, ...

  5. JavaSE回顾及巩固的自学之路(四)——————方法和数组,面向对象

    今天是2018.03.31,emmmmmm.好像距离上一次写Javase回顾总结已经好久好久过去,差一点就以为要停更了,哈哈哈.        其实呢,最近是真的好忙(额,这段时间觉得自己一直在学习) ...

  6. SQL语句——重复记录

    1.查找重复记录: (按id查找) select * from user_info where id in ( select id from user_info group by id ) 即:sel ...

  7. delphi-TTcpServer与TTcpClient

    最简单的TTcpServer与TTcpClient通信实例-Delphi_海盗船长_新浪博客http://blog.sina.com.cn/s/blog_5383794d0100nt9u.html d ...

  8. js遍历对象的方法

    1. for ... in 语句 for (let variable in object)  { ... } https://developer.mozilla.org/zh-CN/docs/Web/ ...

  9. 改环境变量改出问题了,vi,ls这些命令都不能用了,怎么办

    1.出现这个问题肯定是以前的基本环境变量都用不了了(大部分情况就是多了一个空格) 解决办法: cd /usr/bin 下执行vi命令  修改环境变量  然后source /etc/profile   ...

  10. ssh Jetson tk1

    背景: 因为TK1要放到智能车上,不方便打开roscore和各个节点,因此需要PC远程控制. 方法: 在PC端用ssh命令登录: (1)命令sudo ssh tegra-ubuntu.local(te ...