luoheng
10/6/2019 - 10:10 AM

preorder

"""
# Definition for a Node.
class Node:
    def __init__(self, val, children):
        self.val = val
        self.children = children
"""
class Solution:
    def preorder(self, root: 'Node') -> List[int]:
        if root is None:
            return []
        lists, stack = [], [root]
        while stack != []:
            cur = stack.pop()
            lists.append(cur.val)
            if cur.children:
                stack.extend(reversed(cur.children))
        return lists