Skip to content

Commit 0a6d295

Browse files
committed
add T104
1 parent 74b38bf commit 0a6d295

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

数据结构篇/二叉树.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
104.二叉树的最大深度[二叉树的最大深度](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/)
2+
3+
给定一个二叉树,找出其最大深度。二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。**说明:** 叶子节点是指没有子节点的节点。
4+
5+
> 给定二叉树 [3,9,20,null,null,15,7]
6+
>
7+
> 3
8+
> / \
9+
> 9 20
10+
> / \
11+
> 15 7
12+
> 返回它的最大深度 3 。
13+
14+
```js
15+
var maxDepth = function(root) { //递归
16+
if(root === null){
17+
return 0;
18+
}
19+
return Math.max(maxDepth(root.left), maxDepth(root.right))+1;
20+
};
21+
```
22+

0 commit comments

Comments
 (0)