104. Maximum Depth of Binary Tree
来源:互联网 发布:mp3铃声截取软件 编辑:程序博客网 时间:2024/05/08 23:18
/**
* 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 max(int x,int y)
{
return x>y ? x : y;
}
int Depth(TreeNode* node)
{
int max_Depth = 0;
if(node)
{
max_Depth++;
if(node->left || node->right)
max_Depth += max(Depth(node->left), Depth(node->right));
}
return max_Depth;
}
int maxDepth(TreeNode* root) {
if(!root)
return 0;
return Depth(root);
}
* 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 max(int x,int y)
{
return x>y ? x : y;
}
int Depth(TreeNode* node)
{
int max_Depth = 0;
if(node)
{
max_Depth++;
if(node->left || node->right)
max_Depth += max(Depth(node->left), Depth(node->right));
}
return max_Depth;
}
int maxDepth(TreeNode* root) {
if(!root)
return 0;
return Depth(root);
}
};
【总结】二叉树的深度,基础。
0 0
- [LeetCode]104.Maximum Depth of Binary Tree
- 104.Maximum Depth of Binary Tree
- 【LeetCode】104.Maximum Depth of Binary Tree
- [Leetcode] 104. Maximum Depth of Binary Tree
- LeetCode --- 104. Maximum Depth of Binary Tree
- LeetCode 104. Maximum Depth of Binary Tree
- 104.Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 104.Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- leetCode 104. Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree LeetCode
- 104. Maximum Depth of Binary Tree LeetCode
- 104. Maximum Depth of Binary Tree
- LeetCode 104. Maximum Depth of Binary Tree
- leetcode:104. Maximum Depth of Binary Tree
- 【数组】C99的新特性:指定初始化项目
- Get Paid to Read Ads with 7 Most Trusted PTC Sites
- 【牛腩】当前上下文中不存在名称"..."
- android Material Design (材质设设计)
- 如何安全的存储用户的密码
- 104. Maximum Depth of Binary Tree
- android 属性动画 vs 延时实现动画
- SpringMVC-forward和redirect
- 线程池的设计
- inet_ntoa函数陷阱
- 秋夕名節에 奉仕作業團活動1938
- Hexo在github上构建免费的Web应用
- Android下拉刷新上拉加载更多的扩展ListView
- 【JAVA】32、对象的创建与使用