leetCode104. 二叉树的最大深度
给定一个二叉树,找出其最大深度。
二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。
说明: 叶子节点是指没有子节点的节点。
示例:
给定二叉树 [3,9,20,null,null,15,7]
,
3
/ \
9 20
/ \
15 7
返回它的最大深度 3 。
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {number}
*/
var maxDepth = function(root) {
return computedDepeth(root,0)
};
var computedDepeth = function(root,deep){
if(root == null) return deep;
return Math.max(computedDepeth(root.left,deep+1),computedDepeth(root.right,deep+1))
}
leetCode104. 二叉树的最大深度的更多相关文章
- [Swift]LeetCode104. 二叉树的最大深度 | Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- leetcode-104.二叉树最大深度 · BTree + 递归
easy 题就不详细叙述题面和样例了,见谅. 题面 统计二叉树的最大深度. 算法 递归搜索二叉树,返回左右子树的最大深度. 源码 class Solution { public: int maxDep ...
- LeetCode 104. 二叉树的最大深度(Maximum Depth of Binary Tree)
104. 二叉树的最大深度 104. Maximum Depth of Binary Tree 题目描述 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说 ...
- [LeetCode] Maximum Depth of Binary Tree 二叉树的最大深度
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- lintcode :二叉树的最大深度
题目: 二叉树的最大深度 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的距离. 样例 给出一棵如下的二叉树: 1 / \ 2 3 / \ 4 5 这个二叉树的最大深度为3. 解 ...
- Leetcode 104. Maximum Depth of Binary Tree(二叉树的最大深度)
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- 【easy】104. Maximum Depth of Binary Tree 求二叉树的最大深度
求二叉树的最大深度 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; ...
- LeetCode(104):二叉树的最大深度
Easy! 题目描述: 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说明: 叶子节点是指没有子节点的节点. 示例:给定二叉树 [3,9,20,null, ...
- [Leetcode] Maximum depth of binary tree二叉树的最大深度
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
随机推荐
- Mac 10.13.6 安装 cocoapods
卸载pod sudo rm -fr ~/Library/Caches/CocoaPods/ sudo rm -fr ~/.cocoapods/repos/master/ sudo rm -fr Pod ...
- hive 非等值连接, 设置hive为nonstrict模式
1 数据准备 create table stocks(id int, date string,price string, company string); insert into table stoc ...
- Spock - Document -06 - Modules
Modules Peter Niederwieser, The Spock Framework TeamVersion 1.1 Guice Module Integration with the Gu ...
- getParameter和getAttribute的区别
1.getAttribute 是取得jsp中 用setAttribute 设定的attribute 2.parameter得到的是String:attribute得到的是object 3.reques ...
- Linux下安装gradle
Linux下安装gradle 1. Gradle 是以 Groovy 语言为基础,面向Java应用为主.基于DSL(领域特定语言)语法的自动化构建工具 下面就描述一下如何在linux环境下安装配置gr ...
- kali在执行 apt-get update 命令时报错的解决方法
报错内容: root@kali:~# apt-get updateGet:1 http://kali.mirror.garr.it/mirrors/kali kali-rolling InReleas ...
- WPF-MVVM-ICommand接口实现
一 接口分析MVVM框架的目的就是让视图和业务逻辑分离,各干各的.那么怎样实现分离呢,精髓就是绑定ICommand.先看一下ICommand接口的定义: // // 摘要: // 定义一个命令. [T ...
- dataframe基础
1 df[i] 其中i是0,1,2,3,... 此时选中的是dataframe的第i列 2 dataframe查看每一列是否有缺失值 temp = data.isnull().any() #列中 ...
- Http长连接
1.Http长连接 Http的请求时在TCP连接上进行发送的,TCP的连接分为长连接和短连接 打开www.baidu.com,查看Connection ID 如下图. Connection ID代表T ...
- [总结] Synchronized汇总
Java中的每一个对象都可以作为锁. 1对于同步方法,锁是当前实例对象. 2对于静态同步方法,锁是当前对象的Class对象. 3对于同步方法块,锁是Synchonized括号里配置的对象. 当一个线程 ...