public int maxDepth(TreeNode root) {
return order(root, 0);
}
public int order(TreeNode node, int depth) {
if(node == null) {
return depth;
}
depth++;
int d1 = order(node.left, depth);
int d2 = order(node.right, depth);
return Math.max(d1, d2);
}
深度优先搜索,把左右子树最大深度往上传。