(java)leetcode Maximum Depth of Binary Tree
来源:互联网 发布:python 伯乐 编辑:程序博客网 时间:2024/05/16 00:44
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和BFS都可以,我是采用的BFS
代码如下 (已通过leetcode)
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public int maxDepth(TreeNode root) {
int maxdepth=0;
if(root==null) return 0;
int l=maxDepth(root.left);
int r=maxDepth(root.right);
return l>r?l+1:r+1;
}
}
0 0
- [Leetcode] Maximum Depth of Binary Tree (Java)
- [LeetCode][Java] Maximum Depth of Binary Tree
- LeetCode|Maximum Depth of Binary Tree-java
- (java)leetcode Maximum Depth of Binary Tree
- leetcode:Maximum Depth of Binary Tree 【Java】
- Leetcode - Tree - Maximum Depth of Binary Tree
- [leetcode][tree] Maximum Depth of Binary Tree
- 【leetcode】【Maximum Depth of Binary Tree】java stack类
- Leetcode:104. Maximum Depth of Binary Tree(JAVA)
- LeetCode 104 Maximum Depth of Binary Tree JAVA
- leetcode Maximum Depth of Binary Tree java实现
- LeetCode 104 -Maximum Depth of Binary Tree ( JAVA )
- 【Leetcode】:104. Maximum Depth of Binary Tree 问题 in JAVA
- leetcode-java-104. Maximum Depth of Binary Tree
- LeetCode之Maximum Depth of Binary Tree(Java版)
- [LeetCode-104]Maximum Depth of Binary Tree (java)
- LeetCode 104. Maximum Depth of Binary Tree java soluiton
- [leetcode]104. Maximum Depth of Binary Tree@Java解题报告
- linux下文件的创建时间、访问时间、修改时间和改变时间
- 欢迎使用CSDN-markdown编辑器
- 抓交通肇事犯
- 数据结构之伸展树
- 07-图4 哈利·波特的考试
- (java)leetcode Maximum Depth of Binary Tree
- MEGAMALL OpenCart 自适应主题模板 ABC-0692
- String ->date: 思想:把日期装换成字符串
- HTTP协议详解
- Android 我的第一个 NDK 程序 (AndroidStudio)
- JDBC连接Oracle数据库,查看表结构,调用存储过程
- c++ new的使用
- 你的理想在哪
- bzoj-1006 神奇的国度