本文研究的总结,欢迎转载,但请注明出处:http://blog.csdn.net/pistolove/article/details/41964475

Maximum Depth of Binary Tree

Given a binary tree, find its maximum depth.

The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

思路:

(1)题意为找到二叉树最大深度:即为从树根到叶子节点的最大路径。

(2)该题思路和遍历二叉树和寻找二叉树最短深度类似,能够參照二叉树按层次遍历实现http://blog.csdn.net/pistolove/article/details/41929059

(3)为了求得二叉树最大深度。本文也是考虑运用二叉树按层次遍历的思想,二叉树遍历层次的次数即为二叉树的最大深度,这里非常easy理解。

(4)基本的解题思路还是二叉树按层次遍历。本文仅仅只是顺手把其拿过来使用罢了。希望对你有所帮助。

谢谢。

算法代码实现例如以下所看到的:

//最大深度
public static int getDeep(TreeNode root){
if(root==null) return 0;
int level = 0;
LinkedList<TreeNode> list = new LinkedList<TreeNode>();
list.add(root);
int first = 0;
int last = 1;
while(first<list.size()){
last = list.size();
while(first<last){
if(list.get(first).left!=null){
list.add(list.get(first).left);
}
if(list.get(first).right!=null){
list.add(list.get(first).right);
}
first++;
}
level++;
}
return level;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

Lettcode_104_Maximum Depth of Binary Tree的更多相关文章

  1. [LeetCode] Minimum Depth of Binary Tree 二叉树的最小深度

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

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

  3. [LintCode] Maximum Depth of Binary Tree 二叉树的最大深度

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  4. [Leetcode][JAVA] Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree

    Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...

  5. LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree

    LeetCode:Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth ...

  6. LEETCODE —— binary tree [Same Tree] && [Maximum Depth of Binary Tree]

    Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary tre ...

  7. 33. Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree

    Minimum Depth of Binary Tree OJ: https://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ Give ...

  8. Leetcode 111 Minimum Depth of Binary Tree 二叉树

    找出最短的从叶子到根的路径长 可以回忆Maximum Depth of Binary Tree的写法,只不过在!root,我把它改成了10000000,还有max函数改成了min函数,最后的值如果是1 ...

  9. Leetcode | Minimum/Maximum Depth of Binary Tree

    Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...

随机推荐

  1. Project Euler 501 Eight Divisors (数论)

    题目链接: https://projecteuler.net/problem=501 题意: \(f(n)\) be the count of numbers not exceeding \(n\) ...

  2. angular 创建服务

    一:新建服务模块和服务文件 ng g module services --spec=false ng g service services/quote --spec=false 二:在quote.se ...

  3. django-rest-framework框架 第一篇

    本课件是为了教学任务自己写的学习django-rest-framework框架. 方便自己授课,也成为学生的复习教程. 本课程学习后:具有REST编程思维:并可以通过django及专业的django- ...

  4. 再记AE与AO的区别与联系

    原文地址:转:ArcObjects与ArcEngine作者:梦游   ArcObjects(简称AO),一般都是指ArcGIS Desktop版本的组件开发集,即需要安装ArcGIS桌面版软件后才能安 ...

  5. UVA 11090 Going in Cycle!!(Bellman-Ford推断负圈)

    题意:给定一个n个点m条边的加权有向图,求平均权值最小的回路. 思路:使用二分法求解.对于每个枚举值mid,推断每条边权值减去mid后有无负圈就可以. #include<cstdio> # ...

  6. matlab 音频处理

    1. 读取与播放 load gong.mat; % y 42028x1 double soundsc(y); % 可调节其频率 soundsc(y, 2*Fs); 读取 .wav 等音频:audior ...

  7. 云服务器搭建 Nginx 静态网站

    第一步:安装 Nginx 在 CentOS 上,可直接使用 yum 来安装 Nginx(当然也可以通过下载压缩包.解压.编译的方式安装,不过太麻烦了) yum install nginx -y 第二步 ...

  8. 同一master,两个slave的server_id相同问题处理

    错误日志报错如下: 2017-09-15 18:45:59 1660 [Note] Slave I/O thread: Failed reading log event, reconnecting t ...

  9. POJ 2014 Flow Layout 模拟

    http://poj.org/problem?id=2014 嘻嘻2014要到啦,于是去做Prob.ID 为2014的题~~~~祝大家新年快乐~~ 题目大意: 给你一个最大宽度的矩形,要求把小矩形排放 ...

  10. 我的MFC/C++学习笔记 http://blog.bccn.net/CrystalFan/6909

    2009.07.31 ------------------------------------------------------------------------------------ No.1 ...