luoheng
10/6/2019 - 10:04 AM

postorder

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