Skip to content

Commit cfb0f00

Browse files
committed
update
1 parent ba727ed commit cfb0f00

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

34. 二叉树的层序遍历.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Solution:
1717
while queue:
1818
n = len(queue)
1919
level = []
20-
#遍历遍历该层所有节点
20+
#遍历该层所有节点
2121
for i in range(n):
2222
node = queue.pop(0)
2323
if node:

35. 二叉树的最大深度.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
***给定一个二叉树,找出其最大深度。***
2+
3+
![algo17](./images/algo17.jpg)
4+
5+
```
6+
如何理解递归:
7+
如果一个问题A可以分解为若干个子问题B、C、D,你可以假设子问题B、C、D已经解决。而且,你只需要思考问题A与子问题B、C、D两层之间的关系即可,
8+
不需要一层层往下思考子问题与子子问题,子子问题与子子子问题之间的关系。屏蔽掉递归细节,这样子理解起来就简单多了。
9+
递归的一个非常重要的点就是:不去管函数的内部细节是如何处理的,我们只看其函数作用以及输入与输出。
10+
```
11+
12+
```
13+
# Definition for a binary tree node.
14+
# class TreeNode:
15+
# def __init__(self, val=0, left=None, right=None):
16+
# self.val = val
17+
# self.left = left
18+
# self.right = right
19+
class Solution:
20+
def maxDepth(self, root: Optional[TreeNode]) -> int:
21+
if not root:
22+
return 0
23+
return max(self.maxDepth(root.left), self.maxDepth(root.right))+1
24+
```

images/algo17.jpg

5.83 KB
Loading

0 commit comments

Comments
 (0)