给定一个二叉树,找出其最大深度。

二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。

说明: 叶子节点是指没有子节点的节点。

示例:
给定二叉树 [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. 二叉树的最大深度的更多相关文章

  1. [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 ...

  2. leetcode-104.二叉树最大深度 · BTree + 递归

    easy 题就不详细叙述题面和样例了,见谅. 题面 统计二叉树的最大深度. 算法 递归搜索二叉树,返回左右子树的最大深度. 源码 class Solution { public: int maxDep ...

  3. LeetCode 104. 二叉树的最大深度(Maximum Depth of Binary Tree)

    104. 二叉树的最大深度 104. Maximum Depth of Binary Tree 题目描述 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说 ...

  4. [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 ...

  5. lintcode :二叉树的最大深度

    题目: 二叉树的最大深度 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的距离. 样例 给出一棵如下的二叉树: 1 / \ 2 3 / \ 4 5 这个二叉树的最大深度为3. 解 ...

  6. 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 ...

  7. 【easy】104. Maximum Depth of Binary Tree 求二叉树的最大深度

    求二叉树的最大深度 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; ...

  8. LeetCode(104):二叉树的最大深度

    Easy! 题目描述: 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说明: 叶子节点是指没有子节点的节点. 示例:给定二叉树 [3,9,20,null, ...

  9. [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 ...

随机推荐

  1. TIME_WAIT

    前言 请说说你对TCP连接中time_wait状态的理解 解答: 先上TCP的状态变迁图 1. time_wait状态如何产生? 由上面的变迁图,首先调用close()发起主动关闭的一方,在发送最后一 ...

  2. 网络编程三 Socket

    1.根据netstat端口的找到进程号---->根据进程号找到进程名称-------->终止进程 1) netstat    最后一列是5432 C:\Users\Administrato ...

  3. jQuery之基础核心(demo)

    jQuery之基础核心     作者的热门手记 jQuery之基础核心(demo)   本文主要简单的介绍下jQuery一些基础核心,大致了解jQuery使用模式.适用于有HTML.CSS.javas ...

  4. c语言题库---- 函数

    ---恢复内容开始--- 1.编写一个函数,功能为返回两个int类型参数的最大的值 #include <stdio.h>int FindMax( int a, int b); int ma ...

  5. c++ 创建线程以及参数传递

    //创建线程,传递参数 DWORD dwThreadID = ; HANDLE hThread = CreateThread(NULL, , MonitorThreadFunction, , & ...

  6. nvm 知识点

    事项 作用 curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash 安装nvm comm ...

  7. 17.3 删除没用的project

    1.删除某一个或多个无用的project(历史project) 用十六进制编辑器打开"C:\Users\Baymax\Documents\Source Insight 4.0\Project ...

  8. 使用QTP12.2录制windows applications,没有脚本产生

    使用QTP12.2录制windows applications,没有脚本产生解决方案:关闭电脑的杀毒软件和安全卫士,再进行录制,所有步骤录制成功.录制QTP自带程序flight,选择windows a ...

  9. 利用R与SAS进行关联规则挖掘

    一.利用R进行关联规则挖掘 数据结构如下: (共9个itemsets,5个items) 首先读入数据: demodata = read.transactions("C:\\Documents ...

  10. 使用excel 数据透视表画图

    ①    打开Excel,选中需要制表的数据,点击“插入”->“数据透视表”          ②    出现下列对话框,点击“确定”          ③    再新的“sheet”表内对“数 ...