Update 55.1 二叉树的深度.md

补充二叉树深度的递归计算规则说明。
This commit is contained in:
CyC2018
2026-10-30 20:18:06 +08:00
parent 4418a35b6b
commit 63e6777d47
+2
View File
@@ -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));