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;
else return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
}
}

本文介绍了一种通过递归算法来查找二叉树的最大深度的方法。最大深度定义为从根节点到最远叶子节点的最长路径上的节点数。
251

被折叠的 条评论
为什么被折叠?



