Maximum Depth of Binary Tree
2015-12-09 16:08
253 查看
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.
/**
* Definition for a binary tree node.
* 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;
int l = maxDepth(root->left);
int r = maxDepth(root->right);
return 1+max(l,r);
}
};
相关文章推荐
- Spring Web MVC
- Android M新控件之AppBarLayout,NavigationView,CoordinatorLayout,CollapsingToolbarLayout的使用
- python基础教程共60课-第18课bool类型转换
- Unix Network Programming(17)---getsockname 和 getpeername函数
- Win7用户要格外当心 微软12更新包含一枚数字证书信任列表补丁
- VC SDI程序在英文版系统不能运行
- Add Digits
- sql Server的一个实验
- SolrCloud简介和搭建指导
- 验证邮箱
- Word提示”您正试图运行的函数包含有宏或需要宏语言“的解决方法
- Java多线程编程
- 常用小方法 or 语法
- linux学习笔记2015-12-09
- androidpn-环境搭建和源码导入与运行
- NDK——起源
- 第十三周--数据结构-Prim算法的验证
- Android(11种)传感器
- easyui ValidateBox validType字段设置多个校验规则
- SpringMVC 事务配置完全详解