mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 11:34:46 +08:00
Update 0104.二叉树的最大深度.md
This commit is contained in:
@ -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
|
||||
```
|
||||
|
||||
迭代法:
|
||||
|
Reference in New Issue
Block a user