lintcode 97 二叉树的最大深度
来源:互联网 发布:淘宝店铺首页全屏轮播 编辑:程序博客网 时间:2024/05/20 04:32
1.
给定一个二叉树,找出其最大深度。
二叉树的深度为根节点到最远叶子节点的距离。
2.求左右子树的深度,取二者较大者加1即是树的深度
3./**
* Definition of TreeNode:
* class TreeNode {
* public:
* int val;
* TreeNode *left, *right;
* TreeNode(int val) {
* this->val = val;
* this->left = this->right = NULL;
* }
* }
*/
class Solution {
public:
/**
* @param root: The root of binary tree.
* @return: An integer
*/
int maxDepth(TreeNode *root) {
// write your code here
if(root==NULL)return 0;
int leftDepth = maxDepth(root -> left) + 1;
int rightDepth = maxDepth(root -> right) + 1;
return max(leftDepth, rightDepth);
}
};
4.同样的运用了递归,然而还是不懂,参考了同学的,大体明白了这个代码的意思
0 0
- lintcode 97 二叉树的最大深度
- [Lintcode] #97 二叉树的最大深度
- LintCode:二叉树的最大深度
- 二叉树的最大深度(LintCode)
- lintcode,二叉树的最大深度
- LintCode-二叉树的最大深度
- lintcode 二叉树的最大深度
- LintCode 二叉树的最大深度
- 二叉树的最大深度-LintCode
- LintCode 二叉树的最大深度
- [lintcode]二叉树的最大深度
- 二叉树的最大深度-LintCode
- [LintCode]97.二叉树的最大深度
- lintcode二叉树的最大深度
- lintcode 97.二叉树的最大深度
- LintCode-剑指Offer-(97)二叉树的最大深度
- Lintcode-递归-97 二叉树的最大深度
- lintcode——二叉树的最大深度
- 【BZOJ 4821】【SDOI 2017】相关分析
- 加载自定义目录下的springmvc.xml配置文件 (2)
- 数组的使用——杨辉三角的Java实现与C语言实现对比
- methods和computed和watch的联系和区别
- iOS 视图控制器转场详解
- lintcode 97 二叉树的最大深度
- 【poj1741】Tree
- ThreadLocal源码解析(一)
- 教程|没有博士学位,照样玩转TensorFlow深度学习
- #211. 数列
- 初探设计模式之单例模式
- 一个经典的java传递问题
- 递归算法
- 变量提升