master-algorithms-py/tries/trie_postorder.py
2023-08-08 17:01:53 -07:00

25 lines
419 B
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# author: bt3gl
def postorder(self, root: 'Node'):
if root is None:
return []
stack, result = [root, ], []
while stack:
node = stack.pop()
if node is not None:
result.append(node.val)
for c in node.children:
stack.append(c)
return result[::-1]