LeetCodeOJ. Maximum Depth of Binary Tree
见问题: https://oj.leetcode.com/problems/maximum-depth-of-binary-tree/
主题概述
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
解题思路
经典数据结构作业题, 当然也是经典的面试题.
源码
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int maxDepth(TreeNode *root) {
if ( root == NULL ) {
return 0;
} else {
int leftDepth = maxDepth(root->left) + 1;
int rightDepth = maxDepth(root->right) + 1; return ( leftDepth > rightDepth ? leftDepth : rightDepth );
}
}
};
LeetCodeOJ. Maximum Depth of Binary Tree的更多相关文章
- [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 ...
- [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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 104. Maximum Depth of Binary Tree(C++)
104. Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is ...
- 【LeetCode练习题】Maximum Depth of Binary Tree
Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the n ...
- leetcode 104 Maximum Depth of Binary Tree二叉树求深度
Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...
随机推荐
- IOS --- 日期时间格式 更改
1.怎样怎样将一个字符串如" 20110826134106"装化为随意的日期时间格式.以下列举两种类型: NSString* string =@"201108261 ...
- WPF 3D:使用变换中的TranslateTransform3D
原文:WPF 3D:使用变换中的TranslateTransform3D 程序效果: WPF 3D中的TranslateTransform3D应该是所有3D变换中最简单的变换,使用起来非常简单,先定义 ...
- effective c++ 条款26 postpone variable definition as long as possible
因为构造和析构函数有开销,所以也许前面定义了,还没用函数就退出了. 所以比较好的方法是用到了才定义.
- CSS设计指南之理解盒子模型
原文:CSS设计指南之理解盒子模型 一.理解盒模型 每一个元素都会在页面上生成一个盒子.因此,HTML页面实际上是由一堆盒子组成的.默认情况下,每个盒子的边框不可见,背景也是透明的,所以我们不能直接看 ...
- BZOJ 2431 HAOI2009 在列的数目的顺序相反 递归
标题效果:乞讨1~n有都布置在物种的数目相反的顺序k计划数 订购f[i][j]对于前者i原子的反向排列的数j计划数 因此,我们将第一i插入的数1~i-1该装置 能生产0~i-1反向对 再就是 f[i] ...
- SAP ABAP规划 SY-REPID与SY-CPROG差额
首先.它的两个解释 sy-repid is the name of the current program. "当前程序的程序名 ...
- SQL Server 2008 R2 跟踪标志
原文:SQL Server 2008 R2 跟踪标志 跟踪标志用于临时设置特定服务器的特征或关闭特定行为.例如,如果启动 SQL Server 的一个实例时设置了跟踪标志 3205,将禁用磁带机的硬件 ...
- Cocos2d-x3.2游戏的核心循环在Application,怎样处理FPS不稳
今天天气非常阴,立即要下雨了,陈吃早点功夫写点东西, 一场秋雨一场寒,十场秋雨要穿棉,各位从今往后多穿点 int Application::run() { if(!applicationDidFini ...
- shuffle一个简单的过程叙述性说明
shuffle它是在map和reduce过程之间.我们看看在这个过程中的步骤,了解在这个问题上不深,有可能是一个错误.忘记修正 1. map map出口key,value,里的context.writ ...
- android Intent.createChooser 应用选择
在微博案例: 1.public void onClickShare(View view) { 2. 3. Intent intent=new Intent(Intent.ACTION_SEND); 4 ...