LeetCode-104:Maximum Depth of Binary Tree
来源:互联网 发布:淘宝里怎么打开链接 编辑:程序博客网 时间:2024/05/16 12:49
原题描述如下:
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.
Subscribe to see which companies asked this question
题意
:给定一个二叉树,找出该树丛根节点到叶子节点深度的最大值
解题思路:
递归求解。
Java代码:
public class Solution {public int maxDepth(TreeNode root) {
if(root == null)return 0;
int leftdepth = maxDepth(root.left);
int rightdepth = maxDepth(root.right);
return leftdepth > rightdepth ? leftdepth+1 : rightdepth+1;
}
}
0 0
- Leetcode 104 Maximum Depth of Binary Tree
- LeetCode(104)Maximum Depth of Binary Tree
- LeetCode 104 Maximum Depth of Binary Tree
- LeetCode: Maximum Depth of Binary Tree [104]
- 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
- 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
- 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
- Leetcode #104 Maximum Depth of Binary Tree
- leetcode 104: Maximum Depth of Binary Tree
- 欢迎使用CSDN-markdown编辑器
- 用PhotoShop制作.pat格式的图片
- Git学习笔记1
- JAVA &&(短路与),&,|,||(短路或)
- [2016ACM多校] HDU5724 博弈论 SG
- LeetCode-104:Maximum Depth of Binary Tree
- 团体程序设计天梯赛-练习集 L3-010. 是否完全二叉搜索树
- 变态跳台阶
- LeetCode 53. Maximum Subarray
- 安卓学习笔记---popwindow类似的三级联动
- iOS核心动画-UIView封装动画
- Build Node.Js web server in Docker containers: nodejs+pm2+mongodb+redis
- [LeetCode] 35. Search Insert Position
- 安卓学习笔记---好看的UI界面