2018-03-10 求二叉树深度
2018-03-10 本文已影响0人
半瓶酱油
没什么好说的,遍历一层加1
public int maxDepth(TreeNode root) {
if (root == null) return 0;
return 1 + max(maxDepth(root.left), maxDepth(root.right));
}
private int max(int p, int q) {
return p > q ? p : q;
}