> For the complete documentation index, see [llms.txt](https://cai-sen-se.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cai-sen-se.gitbook.io/leetcode/401-600/559.n-cha-shu-de-zui-da-shen-du.md).

# 559.N叉树的最大深度

<https://leetcode-cn.com/problems/maximum-depth-of-n-ary-tree/>

## 一、层序

```python
"""
# Definition for a Node.
class Node:
    def __init__(self, val=None, children=None):
        self.val = val
        self.children = children
"""
import queue
class Solution:
    def maxDepth(self, root: 'Node') -> int:
        depth =0
        if not root:
            return 0
        q = queue.Queue()
        q.put(root)
        while not q.empty():
            depth += 1
            for _ in range(q.qsize()):
                node = q.get()
                for c in node.children:
                    if c:
                        q.put(c)
        return depth
```
