mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-31 02:53:42 +00:00
Update 55.1 二叉树的深度.md
补充二叉树深度的递归计算规则说明。
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user