104. Maximum Depth of Binary Tree
来源:互联网 发布:java冒烟测试怎么做 编辑:程序博客网 时间:2024/06/05 04:12
题目很简单,是求一个二叉树的最大层数,首先思路就是用迭代的方法,左子树的长度和右子树长度比较之后取最大值,然后加一即为二叉树的最大层数。
java代码如下(运行时间1ms,并不是很快)
public int maxDepth(TreeNode root) {
if(root==null) return 0;
else {
int maxleft = maxDepth(root.left);
int maxright = maxDepth(root.right);
return Math.max(maxleft+1, maxright+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
- 基于VirtualBox安装CentOS 6系统
- java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
- vue 开发:axios前后端数据处理
- 阶段总结——软件工程视频(一)
- MyEclipse新建工作空间后的配置详细步骤
- 104. Maximum Depth of Binary Tree
- python中字符串一些基础方法的使用
- Nginx的优点
- 你的流量加密尚需功能再升级
- 2017.10.30 学习笔记
- 基于数据库的分布式消息队列
- 44-继承中的访问级别
- java实现excel下载和上传的工具类
- 选数