最深二叉树 (Maximum Depth of Binary Tree)
2014-10-09 12:51
267 查看
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.
翻译: 给定一个二叉树,找到其深度。
此题比较简单,实现如下:
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public int maxDepth(TreeNode root) {
if(null == root) return 0;
return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
}
}
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
翻译: 给定一个二叉树,找到其深度。
此题比较简单,实现如下:
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public int maxDepth(TreeNode root) {
if(null == root) return 0;
return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
}
}
相关文章推荐
- 【LeetCode 104_二叉树_遍历】Maximum Depth of Binary Tree
- LeetCode----Maximum Depth of Binary Tree 求二叉树最大深度
- LeetCode:104_Maximum Depth of Binary Tree | 二叉树的最大深度 | Easy
- 104/111 Maximum/Minimum Depth of Binary Tree(二叉树求深度)
- LeetCode 104 Maximum Depth of Binary Tree(二叉树的最大深度)
- Leetcode 104 Maximum Depth of Binary Tree 二叉树
- lintcode maximum-depth-of-binary-tree 二叉树的最大深度
- 【二叉树的递归】02二叉树的最大深度【Maximum Depth of Binary Tree】
- Maximum Depth of Binary Tree(二叉树的最大深度)
- [Leetcode] Maximum depth of binary tree二叉树的最大深度
- Maximum Depth of Binary Tree 二叉树的最大深度
- leetcode_104题——Maximum Depth of Binary Tree (二叉树,递归,队列,还有递归没想出来)
- Maximum Depth of Binary Tree--二叉树的深度
- [LintCode] Maximum Depth of Binary Tree 二叉树的最大深度
- 求二叉树的最大深度 Maximum Depth of Binary Tree
- Leetcode 104 Maximum Depth of Binary Tree 二叉树的最大深度
- [LeetCode][二叉树]Maximum Depth of Binary Tree
- LinCode Maximum Depth of Binary Tree 二叉树的最大深度
- Maximum Depth of Binary Tree 求二叉树的最大深度
- [LeetCode-104] Maximum Depth of Binary Tree(二叉树最大深度)