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.
Note: A leaf is a node with no children.
public int maxDepth(TreeNode root) {
/**
* 求树的高度
* 把大问题分解成小问题,树的高度是从子树的高度得到的
*/
if (root == null) {
return 0;
}else {
return Math.max(1+maxDepth(root.left),1+maxDepth(root.right));
}
}