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

int res = 0;
public int sumOfLeftLeaves(TreeNode root) {
if (root==null) return res;
leftSum(root,false);
return res;
}
private void leftSum(TreeNode root,boolean flag)
{
if (root.left==null&&root.right==null&&flag)
res+=root.val;
if (root.left!=null)
leftSum(root.left,true);
if (root.right!=null)
leftSum(root.right,false);
}

[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. 17.java设计模式之观察者模式

    基本需求: 气象站可以将每天测量到的温度,湿度,气压等等,以公告的形式发布出去(比如发布到自己的网站或第三方) 需要设计开放型API,便于其他第三方也能接入气象站获取数据 提供温度.气压和湿度的接口 ...

  2. 20200116_centos7.2 下 mysql_5.7修改root密码

    1. 需改my.cnf文件 [root@rakinda-iot-platform ~]# vim /etc/my.cnf 2. 新增一行, 登录时跳过密码, 保存后退出, 重启mysql system ...

  3. zookeeper基础笔记

    一.安装 1.安装jdk 2.安装Zookeeper 3.单机模式(stand-alone):安装目录/conf   复制 zoo_sample.cfg 并粘贴到当前目录下,命名zoo.cfg. 二. ...

  4. 老猿学5G:3GPP和中国移动5G计费架构概览

    ☞ ░ 前往老猿Python博文目录 ░ 一.引言 老猿学5G这个专栏主要记录笔者因工作原因学习了解5G计费相关知识,文章按时间顺序循序渐进的介绍5G基础概念以及5G计费相关知识,该专栏前期已经完结, ...

  5. PyQt(Python+Qt)学习随笔:QTreeView树形视图的uniformRowHeights属性

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 uniformRowHeights属性用于控制视图中所有数据项是否保持相同高度,所有高度都与视图中第 ...

  6. 手写Json解析器学习心得

    一. 介绍 一周前,老同学阿立给我转了一篇知乎回答,答主说检验一门语言是否掌握的标准是实现一个Json解析器,网易游戏过去的Python入门培训作业之一就是五天时间实现一个Json解析器. 知乎回答- ...

  7. 团队作业4-Day7

    团队作业4-Day7 项目git地址 1. 站立式会议 2. 项目燃尽图 3. 适当的项目截图 4. 代码/文档签入记录(部分) 5. 每人每日总结 吴梓华:今日补充界面小漏洞,修复部分bug 白军强 ...

  8. 前端webSocket和后台php

    HTTP协议的特性:属于"请求-响应"模型,只有客户端发起了请求消息,服务器才能给出响应消息,没有请求,就没有响应:一个请求消息,服务器只能返回一个响应消息.有些特殊应用场景中,如 ...

  9. Codeforces Round #682 Div2 简要题解

    Contest link A.Specific Tastes of Andre Problem link 题意 构造一个长度为 \(n\) 的序列,使得每个非空子序列的和都被其长度整除. 思路 直接每 ...

  10. centos7 mysql 自动补全

    1 yum -y install epel-release #配置erel源 2 yum -y install python-pip 3 pip install mycli #用pip安装 可能会出现 ...