From 63e6777d470eefac9a59e65d924d7235149836dc Mon Sep 17 00:00:00 2001 From: CyC2018 Date: Fri, 30 Oct 2026 20:18:06 +0800 Subject: [PATCH] =?UTF-8?q?Update=2055.1=20=E4=BA=8C=E5=8F=89=E6=A0=91?= =?UTF-8?q?=E7=9A=84=E6=B7=B1=E5=BA=A6.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 补充二叉树深度的递归计算规则说明。 --- notes/55.1 二叉树的深度.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/notes/55.1 二叉树的深度.md b/notes/55.1 二叉树的深度.md index 3af67c60..d0b2f1f3 100644 --- a/notes/55.1 二叉树的深度.md +++ b/notes/55.1 二叉树的深度.md @@ -10,6 +10,8 @@ ## 解题思路 +树的深度等于左右子树深度的较大值加 1,空树的深度为 0。 + ```java public int calculateDepth(TreeNode root) { return root == null ? 0 : 1 + Math.max(calculateDepth(root.left), calculateDepth(root.right));