弄个flag记录是不是左节点就行

  1. int res = 0;
  2. public int sumOfLeftLeaves(TreeNode root) {
  3. if (root==null) return res;
  4. leftSum(root,false);
  5. return res;
  6. }
  7. private void leftSum(TreeNode root,boolean flag)
  8. {
  9. if (root.left==null&&root.right==null&&flag)
  10. res+=root.val;
  11. if (root.left!=null)
  12. leftSum(root.left,true);
  13. if (root.right!=null)
  14. leftSum(root.right,false);
  15. }

[leetcode]404. Sum of Left Leaves左叶子之和的更多相关文章

  1. 404. Sum of Left Leaves 左叶子之和

    [抄题]: Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are ...

  2. LeetCode404Sum of Left Leaves左叶子之和

    计算给定二叉树的所有左叶子之和. 示例: 3 / \ 9    20 / \ 15   7 在这个二叉树中,有两个左叶子,分别是 9 和 15,所以返回 24 class Solution { pub ...

  3. LeetCode 404. Sum of Left Leaves (左子叶之和)

    Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two l ...

  4. [LeetCode] Sum of Left Leaves 左子叶之和

    Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two l ...

  5. LeetCode 404. Sum of Left Leaves (C++)

    题目: Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are t ...

  6. LeetCode - 404. Sum of Left Leaves

    Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two l ...

  7. 16. leetcode 404. Sum of Left Leaves

    Find the sum of all left leaves in a given binary tree. Example:     3    / \   9  20     /  \    15 ...

  8. LeetCode 404. 左叶子之和(Sum of Left Leaves)

    404. 左叶子之和 404. Sum of Left Leaves LeetCode404. Sum of Left Leaves 题目描述 计算给定二叉树的所有左叶子之和. 示例: 3 / \ 9 ...

  9. [Swift]LeetCode404. 左叶子之和 | Sum of Left Leaves

    Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two l ...

随机推荐

  1. unittest框架中读取有特殊符号的配置文件内容的方法-configparser的RawConfigParser类应用

    在搭建Unittest框架中,出现了一个问题,配置文件.ini中,出现了特殊字符如何处理? 通过 1.configparser的第三方库对应的ConfigParser类,无法完成对特殊字符的读取: # ...

  2. 从0开始带你成为JVM实战高手(百度网盘)

    狸猫技术窝<从0开始带你成为JVM实战高手> 之前写过几篇 JVM 相关的文章,最近复盘的时候,发现狸猫技术窝<从0开始带你成为JVM实战高手>真的不错,然后就在网上找了一下( ...

  3. Python中super()或object.__new__报TypeError: object.__new__() takes no arguments错误的解决方案

    出现这种情况是调用object类__new__方法参数传递多了导致: 一般是使用了类似super().new(cls,*args,**kwargs) 或object.new(self,*args,** ...

  4. DVWA学习笔记

    原来装的DVWA没有认认真真地做一遍,靶场环境也有点问题了,到github上面重新下载了一遍:https://github.com/ethicalhack3r/DVWA 复习常见的高危漏洞,产生,利用 ...

  5. espcms代码审计第一弹

    以前的代码审计都是在CTF比赛题里面进行对于某一段代码的审计,对于后端php整体代码和后端整体架构了解的却很少,所以有空我都会学习php的代码审计,以提高自己 环境就直接用的是phpstudy,学习的 ...

  6. 攻防世界 web进阶区 lottery

    首先进入题目的页面. 按其要求登录.然后看到以下界面. 御剑扫描目录,发现了robots.txt (robots协议) ,进入查看 进入.git/目录,用神器 GitHack 下载文件. 然后查看源码 ...

  7. mybatis逆向工程运行

    命令: mvn mybatis-generator:generate 项目结构: generatorConfig.xml内容示例 <?xml version="1.0" en ...

  8. Linux 上安装 mysql

    1.通过 yum 命令安装 mysql 可以先通过 yum list |grep mysql 方式查看有哪些版本的 mysql 2.安装 mysql yum install mysql-server ...

  9. STL—— 容器(vector)数据插入insert()方法 的返回值

    vector 容器下的 insert() 方法拥有返回值,由于insert() 方法拥有4种重载函数,他的返回值不尽相同. 第一种,插入单个元素后的返回值: 1 #include <iostre ...

  10. 如何使用交易开拓者(TB)开发数字货币策略

    更多精彩内容,欢迎关注公众号:数量技术宅.想要获取本期分享的完整策略代码,请加技术宅微信:sljsz01 为何使用交易开拓者(TB)作为回测工具 交易开拓者(后文以TB简称)是一个支持国内期货市场K线 ...