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 ...
随机推荐
- webpack使用中遇到的问题
http://ife.baidu.com/note/detail/id/534 https://blog.csdn.net/hreticent/article/details/80489851
- 前端---JQuery初识
---恢复内容开始--- BOM JQuery认识 JQuery基本选择器 JQuery高级选择器 1.javascript基础部分包括三个部分: ECMAScript:JavaScript的语法标准 ...
- Codeforces 1105C: Ayoub and Lost Array(递推)
time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: sta ...
- 关于crontab
crontab是一个linux系统自带的定时执行任务的功能,有两种方法可以实现 1: 使用命令 crontab -e 然后直接编辑定时脚本,实际是编辑/var/spool/cron 目录下,一个和用户 ...
- 关于pycharm中缩进、粘贴复制等文本编辑功能部分失效的解决办法
有可能是同时安装了vim,冲突导致: 在seetings中点击Plugins,搜索vim卸载后功能恢复
- 选择排序-C#
选择排序包括:简单选择排序和堆排序 简单选择排序: 基本思路:从所有序列中先找到最小的,然后放到第一个位置.之后再看剩余元素中最小的,放到第二个位置……以此类推 /// <summary> ...
- RGB颜色名称与色值对应表
实色效果 英文名称 R.G.B 16色 实色效果 英文名称 R.G.B 16色 Snow 255 250 250 #FFFAFA PaleTurquoise1 187 255 255 #BBF ...
- HISI VENC 实际输出帧率控制
https://blog.csdn.net/spy_007_/article/details/83688287 平台:HI3516EV100 SDK : Hi3516CV300_SDK_V1.0.2. ...
- AllocateHWnd SetTimer API
unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- CUDA 编程
作者:MingChaoSun 原文:https://blog.csdn.net/sunmc1204953974/article/details/51000970 一.CPU和GPU 上图是CPU与GP ...