leetcode-Maximum Depth of Binary Tree
来源:互联网 发布:网络兼职招聘网站 编辑:程序博客网 时间:2024/06/08 18:21
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.
求树的最大深度,也就是求左子树或右子树的最大深度,通过递归,得到最大深度。
public class Solution { public int maxDepth(TreeNode root) { if(root==null) return 0; if(root.left==null&&root.right==null) return 1; else { return (1+Math.max(maxDepth(root.left),maxDepth(root.right))); } }}
0 0
- Leetcode - Tree - Maximum Depth of Binary Tree
- [leetcode][tree] Maximum Depth of Binary Tree
- LeetCode Maximum Depth of Binary Tree
- [Leetcode] Maximum Depth of Binary Tree
- leetcode 24: Maximum Depth of Binary Tree
- [LeetCode] Maximum Depth of Binary Tree
- Leetcode 104 Maximum Depth of Binary Tree
- 【leetcode】Maximum Depth of Binary Tree
- [leetcode]Maximum Depth of Binary Tree
- [LeetCode]Maximum Depth of Binary Tree
- [leetcode]Maximum Depth of Binary Tree
- Leetcode: Maximum Depth of Binary Tree
- LeetCode-Maximum Depth of Binary Tree
- [leetcode] Maximum Depth of Binary Tree
- LeetCode - Maximum Depth of Binary Tree
- LeetCode:Maximum Depth of Binary Tree
- LeetCode | Maximum Depth of Binary Tree
- 【leetcode】Maximum Depth of Binary Tree
- 十分钟搞清字符集和字符编码
- 【数据结构与算法分析】1.4 用printOut函数输出任意实数
- 第八周项目3 顺序串算法(3)
- Web服务器
- java连接mysql删除操作
- leetcode-Maximum Depth of Binary Tree
- 关于Android中的枚举【4种】
- php上传七牛实例
- Android面试题总结
- pluto实现分析(2)——代码函数调用关系
- Java Iterator与ListIterator的主要区别
- JQUERY在线引用地址
- 设计模式之原型模式(深入理解OC中的NSCopying协议以及浅拷贝、深拷贝)
- java处理高并发高负载类网站的优化方法