luoheng
10/7/2019 - 6:41 AM

levelOrder

"""
# Definition for a Node.
class Node:
    def __init__(self, val, children):
        self.val = val
        self.children = children
"""
class Solution:
    def levelOrder(self, root: 'Node') -> List[List[int]]:
        if root is None:
            return []
        result, cur = [], [root]
        while cur:
            next, temp = [], []
            for node in cur:
                temp.append(node.val)
                next += node.children
            result.append(temp)
            cur = next
        return result