Maximum Depth of Binary Tree
来源:互联网 发布:淘宝蚂蚁花呗怎么关闭 编辑:程序博客网 时间:2024/06/06 07:31
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 binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int maxDepthHelper(TreeNode * node){
if (node==NULL)
return 0;
else{
return max(maxDepthHelper(node->left),
maxDepthHelper(node->right) )+1;
}
}
int maxDepth(TreeNode *root) {
int maximum = maxDepthHelper(root);
return maximum;
}
};
- 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
- arm 体系的汇编
- 关于指针变量的问题
- 数据结构c语言版之简单选择排序
- linux常用命令之一
- $.post()
- Maximum Depth of Binary Tree
- dojo Select下拉菜单项无法选中的原因与解决
- jointjs hello world
- 利用Python进行数据分析——第一章:重要Python库安装配置
- MySQL入门(转载加自己见解)
- 第一个cocos2dx游戏
- Same Tree
- 富贵不能体会
- 电磁阀的慕尼黑