We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3c7bb86 commit c150d9eCopy full SHA for c150d9e
DFS/traditionalDFS/559.md
@@ -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