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. PHP7 学习笔记(四)PHP PSR-4 Autoloader 自动加载

    参考文献: 1.PHP PSR-4 Autoloader 自动加载(中文版) 2.PHP编码规范(中文版)导读 3.PHP-PSR-[0-4]代码规范 基本步骤: (1)在vendor 下新建一个项目 ...

  2. 转--Python标准库之一句话概括

    作者原文链接 想掌握Python标准库,读它的官方文档很重要.本文并非此文档的复制版,而是对每一个库的一句话概括以及它的主要函数,由此用什么库心里就会有数了. 文本处理 string: 提供了字符集: ...

  3. 消除 transition 闪屏

    .css { -webkit-transform-style: preserve-3d; -webkit-backface-visibility: hidden; -webkit-perspectiv ...

  4. JS在Html中使用JavaScript

    一.三种方式 1)<script>元素 2)外部文件 3)文档模式 二.<script>元素 是向HTML页面插入JavaScript的主要方法:HTML 4.01为<s ...

  5. IEEE 802.1X标准

    1.介绍 802.1X是一个IEEE标准,通过对用户进行基于端口的安全认证和对密钥的动态管理,从而实现保护用户用户的位置隐私和身份隐私以及有效保护通信过程中信息安全的目的. 在802.1X协议中,只有 ...

  6. JavaScript之获取表格目标数据(TableDom.getTableData())

    [声明:  1.博文原创 未经同意转载必究,欢迎相互交流] [声明:  2.博主未知情况下转载,需显著处注明博文来源] [声明:  3.谢谢尊重劳动成果,谢谢理解与配合~] 一.背景 在生产过程和生活 ...

  7. Python实现图片压缩

    项目中大量用到图片加载,由于图片太大,加载速度很忙,因此需要对文件进行统一压缩 一:导入包 from PIL import Image import os 二:获取图片文件的大小 def get_si ...

  8. tidb 架构 ~Tidb学习系列(3)

    tidb集群安装测试1 环境 3台机器2 配置   server1 pd服务+tidb-server   server2 tidb-kv   server3 tidb-kv3 环境配置命令   ser ...

  9. Informatic学习总结_day01

    1.forlder 必须open之后才出现  mapping的界面 2.Source Qualifer 3.小技巧 验证自己写的转换格式是否正确 提前过滤一些数据,informatica工具的本质也是 ...

  10. GCC的符号可见性——解决多个库同名符号冲突问题

    引用自:https://github.com/wwbmmm/blog/wiki/gcc_visibility 问题 最近项目遇到一些问题,场景如下 主程序依赖了两个库libA的funcA函数和libB ...