题目链接:https://leetcode.com/problems/maximum-depth-of-binary-tree/
题目:
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 int maxDepth(TreeNode root) {
if (root == null)
return 0;
int h1 = maxDepth(root.left);
int h2 = maxDepth(root.right);
return h1 > h2 ? h1 + 1 : h2 + 1;
}