mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 07:35:35 +08:00
Merge pull request #1802 from ZerenZhang2022/patch-2
Update 0102.二叉树的层序遍历.md
This commit is contained in:
@ -1346,6 +1346,22 @@ class Solution:
|
|||||||
return results
|
return results
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
# LeetCode 429. N-ary Tree Level Order Traversal
|
||||||
|
# 递归法
|
||||||
|
class Solution:
|
||||||
|
def levelOrder(self, root: 'Node') -> List[List[int]]:
|
||||||
|
if not root: return []
|
||||||
|
result=[]
|
||||||
|
def traversal(root,depth):
|
||||||
|
if len(result)==depth:result.append([])
|
||||||
|
result[depth].append(root.val)
|
||||||
|
if root.children:
|
||||||
|
for i in range(len(root.children)):traversal(root.children[i],depth+1)
|
||||||
|
|
||||||
|
traversal(root,0)
|
||||||
|
return result
|
||||||
|
```
|
||||||
java:
|
java:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
|
Reference in New Issue
Block a user