Skip to content

Latest commit

 

History

History
48 lines (35 loc) · 1.11 KB

_590. N-ary Tree Postorder Traversal.md

File metadata and controls

48 lines (35 loc) · 1.11 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : August 26, 2024

Last updated : August 26, 2024


Related Topics : Stack, Tree, Depth-First Search

Acceptance Rate : 80.41 %


Solutions

Python

"""
# Definition for a Node.
class Node:
    def __init__(self, val=None, children=None):
        self.val = val
        self.children = children
"""

class Solution:
    def postorder(self, root: 'Node') -> List[int]:
        def post(curr: 'Node', output: List[int] = []) -> List[int] :
            if not curr :
                return output
            for c in curr.children :
                post(c, output)
            output.append(curr.val)
            return output

        return post(root)