104. Maximum Depth of Binary Tree
来源:互联网 发布:淘宝的拼团在哪里 编辑:程序博客网 时间:2024/06/15 19:39
问题描述:
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.
解题思路:
给定一棵二叉树,求大的深度。顾名思义,dfs递归求,比较左右子树谁最大:l>r?l+1:r+1
class Solution {
public:
int maxDepth(TreeNode* root) {
if(root==NULL) return 0;
int l,r;
l=maxDepth(root->left);
r=maxDepth(root->right);
return l>r?l+1:r+1;
}
};
public:
int maxDepth(TreeNode* root) {
if(root==NULL) return 0;
int l,r;
l=maxDepth(root->left);
r=maxDepth(root->right);
return l>r?l+1:r+1;
}
};
阅读全文
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
- STL中vector的实现及面试问题
- Listener监听器
- excel中vlookup搞定数据匹配
- Window
- Spring和SpringMVC父子容器关系初窥
- 104. Maximum Depth of Binary Tree
- linux安装tomcat Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- 关于Tomcat 启动 Removing obsolete files from server Could not clean server of obsolete 问题解决
- 正则表达式三 :编译
- 解决Swift项目中use_frameworks!冲突的问题
- 通过有趣的对话来学习面向对象的设计原则
- leetcode_110. Balanced Binary Tree
- mysql用户管理(转自-米阳光-)
- spring-framework-reference翻译 22 Web MVC framework