Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ab41c10

Browse files
🐳(tree): 104. 二叉树的最大深度
复盘
1 parent ba9c878 commit ab41c10

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎docs/data-structure/tree/recursion/README.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,25 @@ class Solution(object):
126126
return max(self.maxDepth(root.left), self.maxDepth(root.right)) + 1
127127
```
128128

129+
20210113 复盘:
130+
131+
```python
132+
# Definition for a binary tree node.
133+
# class TreeNode:
134+
# def __init__(self, x):
135+
# self.val = x
136+
# self.left = None
137+
# self.right = None
138+
139+
class Solution:
140+
def maxDepth(self, root: TreeNode) -> int:
141+
if root is None:
142+
return 0
143+
left_depth = self.maxDepth(root.left) + 1
144+
right_depth = self.maxDepth(root.right) + 1
145+
return max(left_depth, right_depth)
146+
```
147+
129148
#### **Go**
130149

131150
```go

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /