// 获取最大深度
public static int getMaxDepth(TreeNode root) {
if (root == null)
return 0;
else {
int left = getMaxDepth(root.left);
int right = getMaxDepth(root.right);
return 1 + Math.max(left, right);
}
}
计算一个二叉树的深度
最新推荐文章于 2025-03-18 11:29:23 发布