Skip to content

Commit c150d9e

Browse files
committed
559
1 parent 3c7bb86 commit c150d9e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

DFS/traditionalDFS/559.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## 559 Maximum Depth of N-ary Tree
2+
3+
#### Description
4+
5+
[link](https://leetcode.com/problems/maximum-depth-of-n-ary-tree/)
6+
7+
---
8+
9+
#### Solution
10+
11+
- See Code
12+
13+
---
14+
15+
#### Code
16+
17+
> 最坏情况:O(n^2)
18+
19+
```python
20+
"""
21+
# Definition for a Node.
22+
class Node:
23+
def __init__(self, val=None, children=None):
24+
self.val = val
25+
self.children = children
26+
"""
27+
class Solution:
28+
def maxDepth(self, root: 'Node') -> int:
29+
if not root:
30+
return 0
31+
if not root.children:
32+
return 1
33+
return max(self.maxDepth(x) for x in root.children) + 1
34+
```

0 commit comments

Comments
 (0)