All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : August 26, 2024
Last updated : August 26, 2024
Related Topics : Stack, Tree, Depth-First Search
Acceptance Rate : 80.41 %
"""
# 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)