Skip to content

Latest commit

 

History

History
38 lines (35 loc) · 1.01 KB

n-ary-tree-postorder-traversal.md

File metadata and controls

38 lines (35 loc) · 1.01 KB
title date tags
n-ary-tree-postorder-traversal
8100-01-01
计算机
算法
LeetCode

简述

后序遍历 N 叉树 n-ary-tree-postorder-traversal 英文 中文

收获

二叉树

代码

"""
# Definition for a Node.
class Node(object):
    def __init__(self, val, children):
        self.val = val
        self.children = children
"""
class Solution(object):
    def postorder(self, root):
        """
        :type root: Node
        :rtype: List[int]
        """
        if root is None:
            return []
        
        stack, output = [root, ], []
        while stack:
            root = stack.pop()
            output.append(root.val)
            stack.extend(root.children)
                
        return output[::-1]