一、问题描述
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.
二、问题分析
与 Minimum Depth of Binary Tree非常相似,同样的解法。
三、Java AC 代码
public int maxDepth(TreeNode root) {
return depth(root);
}
public int depth(TreeNode node){
if (node == null) {
return 0;
}
return Math.max(depth(node.left), depth(node.right))+1;
}