[leetcode]404. Sum of Left Leaves左叶子之和
弄个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左叶子之和的更多相关文章
- 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 ...
- LeetCode404Sum of Left Leaves左叶子之和
计算给定二叉树的所有左叶子之和. 示例: 3 / \ 9 20 / \ 15 7 在这个二叉树中,有两个左叶子,分别是 9 和 15,所以返回 24 class Solution { pub ...
- 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 ...
- [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 ...
- 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 ...
- 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 ...
- 16. leetcode 404. Sum of Left Leaves
Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 ...
- LeetCode 404. 左叶子之和(Sum of Left Leaves)
404. 左叶子之和 404. Sum of Left Leaves LeetCode404. Sum of Left Leaves 题目描述 计算给定二叉树的所有左叶子之和. 示例: 3 / \ 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 ...
随机推荐
- 【PSMA】Progressive Sample Mining and Representation Learning for One-Shot Re-ID
目录 主要挑战 主要的贡献和创新点 提出的方法 总体框架与算法 Vanilla pseudo label sampling (PLS) PLS with adversarial learning Tr ...
- JZOJ【NOIP2012模拟8.9】2020.10.5 T1
逐个击破 题目 Description 三大战役的平津战场上,傅作义集团在以北平.天津为中心,东起唐山西至张家口的铁路线上摆起子一字长蛇阵,并企图在溃败时从海上南逃或向西逃窜.为了就地歼敌不让其逃走, ...
- PHP代码审计分段讲解(3)
05 ereg正则%00截断 放上源代码 <?php $flag = "flag"; if (isset ($_GET['password'])) { if (ereg (& ...
- 几句话说明 .NET MVC中ViewData, ViewBag和TempData的区别
ViewData和TempData是字典类型,赋值方式用字典方式, ViewData["myName"] ViewBag是动态类型,使用时直接添加属性赋值即可 ViewBag.my ...
- js数组快速排序和冒泡排序
1.快速排序 var arr = [1, 2, 5, 6, 3, 1, 4]; function mySort(arr) { if (arr.length <= 1) { return arr; ...
- C# 9.0新特性详解系列之五:记录(record)和with表达式
1 背景与动机 传统面向对象编程的核心思想是一个对象有着唯一标识,表现为对象引用,封装着随时可变的属性状态,如果你改变了一个属性的状态,这个对象还是原来那个对象,就是对象引用没有因为状态的改变而改变, ...
- OpenWrt下基于OLSR的Ad-Hoc组网实现网络摄像头多节点访问
文章目录 Ad-Hoc组网配置 摄像头端口映射 PC连接设置 结果 Ad-Hoc组网配置 参照博客 链接: link. 摄像头端口映射 这里使用到了海康网络摄像头,先将网络摄像头的网口连接到任意一个节 ...
- JavaScript:常用的一些数组遍历的方法
常用的一些遍历数组的方法: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- CPU的功能和基本组成结构
目录 CPU的功能 运算器和控制器的功能 CPU的基本结构 运算器的基本结构 控制器的基本结构 整体 本节回顾 CPU的功能 指令控制:完成取指令.分析指令和执行指令的操作,即程序的顺序控制 操作控制 ...
- 九、TestNG超时测试
"超时"表示如果单元测试花费的时间超过指定的毫秒数,那么TestNG将会中止它并将其标记为失败. 使用属性 timeOut = 参数(1s*1000) package com.lc ...