Maximum Depth of Binary Tree
来源:互联网 发布:hdmi矩阵使用方法 编辑:程序博客网 时间:2024/05/18 02:56
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.
Subscribe to see which companies asked this question
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
}
int maxDepth(struct TreeNode* root) {
int count=0;
int h1,h2;
if(!root)//空树
return 0;
h1=maxDepth(root->left);
h2=maxDepth(root->right);
return h1>h2?h1+1:h2+1;
}
0 0
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- 配置文件Struts.xml <result>中type属性 redirect,redirectAction,chain的区别
- SVM实例及Matlab代码
- sleep(n)函数实现
- 彤云垂暮,落日渐歇,秋水潋滟,葳蕤已覆。
- HID键盘底层协议
- Maximum Depth of Binary Tree
- BPDU Gard / BPDU Filter / Root Guard
- windows下遍历当前任务管理器中的服务的列表
- h5端呼起摄像头扫描二维码并解析
- awakeFromNib,自定义xib的UIView和UIViewController 重载它
- C++(2)
- 程序员:如何接手垃圾代码?
- 数据结构的基础学习1
- 如何修改Android启动动画和开机声音