Skip to content

Commit a1628f7

Browse files
committedApr 22, 2019
Leetcode打打卡第二十二天day22_二叉树的最大深度
1 parent 5f25fd8 commit a1628f7

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
 

‎MaximumDepthofBinaryTree.md

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
Time:2019/4/22
3+
Title: Maximum Depth of Binary Tree
4+
Difficulty: Medium
5+
Author:小鹿
6+
---
7+
8+
9+
10+
## 题目:Maximum Depth of Binary Tree(二叉树的最大深度)
11+
12+
Given a binary tree, find its maximum depth.
13+
14+
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
15+
16+
> 给定一个二叉树,找出其最大深度。
17+
>
18+
> 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。
19+
>
20+
> **说明:** 叶子节点是指没有子节点的节点。
21+
22+
**Note:** A leaf is a node with no children.
23+
24+
**Example:**
25+
26+
Given binary tree `[3,9,20,null,null,15,7]`,
27+
28+
```
29+
3
30+
/ \
31+
9 20
32+
/ \
33+
15 7
34+
```
35+
36+
return its depth = 3.
37+
38+
39+
40+
## Solve:
41+
42+
###### ▉ 算法思路
43+
44+
45+
46+
###### ▉ 代码实现
47+
48+
```javascript
49+
var maxDepth = function(root) {
50+
return root === null ? 0 : Math.max(maxDepth(root.left),maxDepth(root.right)) + 1;
51+
};
52+
```
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
87+
88+
89+

0 commit comments

Comments
 (0)
Failed to load comments.