Update 0104.二叉树的最大深度.md

This commit is contained in:
jianghongcheng
2023-05-03 21:48:04 -05:00
committed by GitHub
parent aac7378cb6
commit 5da51519b5

View File

@ -452,14 +452,17 @@ class Solution:
递归法:
```python
class solution:
def maxdepth(self, root: 'node') -> int:
class Solution:
def maxDepth(self, root: 'Node') -> int:
if not root:
return 0
depth = 0
for i in range(len(root.children)):
depth = max(depth, self.maxdepth(root.children[i]))
return depth + 1
max_depth = 1
for child in root.children:
max_depth = max(max_depth, self.maxDepth(child) + 1)
return max_depth
```
迭代法: