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 ...
随机推荐
- $(window).scroll()无法触发问题
在微信端开发中遇到一个这种问题:明明用的公共文件(代码如下图),其他页面每次都能触发这个滚动条$(window).scroll事件,以显示右下角“回到顶部”这个按钮图标 但是,问题来了,最该需要使用“ ...
- PAT乙级考前总结(五)
字符串处理 1003 我要通过! (20 分) “答案正确”是自动判题系统给出的最令人欢喜的回复.本题属于 PAT 的“答案正确”大派送 —— 只要读入的字符串满足下列条件,系统就输出“答案正确”,否 ...
- Python学习笔记,day2
Python学习第二天 一.模块 使用模块前需在代码最前声明(import) 二.数据类型 1.数字 int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2 ...
- 第3章 Data语意学
在C++中经常会遇到一个类的大小问题,关于一个类的大小一般受到三个方面的影响. 语言本身所造成的额外负担,如在虚拟继承中会遇到如派生类中会包含一个指针指向base class subobjec,这样会 ...
- mybatis 中javaType和OfType 的区别
JavaType和ofType都是用来指定对象类型的,但是JavaType是用来指定pojo中属性的类型,而ofType指定的是映射到list集合属性中pojo的类型.pojo类: publiccla ...
- 请用java解析下xml
Java XML简介 XML(EXtensible Markup Language) 可扩展标记语言 可以说是一个文本文件 作用数交互 配置应用程序 Xml解析技术 三种方式 Dom 文档数据 ...
- ios-Nav右上角按钮
右上角的设置按钮 //****************** 右上角保存按钮 ****************** UIButton *rightBtn = [UIButton buttonWithTy ...
- 使用python调用其他脚本
cmd = '<command line string>' print(cmd) p = subprocess.Popen(args=cmd, shell=True, stdout=sub ...
- Taro 生命周期
Taro 新加的生命周期 说明 网址 componentDidShow() 在此生命周期中通过 this.$router.params,可以访问到程序初始化参数 https://nervjs.gith ...
- DNS子域授权
DNS子域授权 当一个域很大时,而且还有上,下层关系,如果所有的记录变更都由某一台服务器来管理的话,那将会是什么样子?就好比一个公司的总经理直接管理公司1000个人的所有事项,恐怕会被累死.所以会在总 ...