From c041716806af8417e94393bb78d6a70014839dfc Mon Sep 17 00:00:00 2001 From: marina <138340846+bt3gl-cryptographer@users.noreply.github.com> Date: Thu, 3 Aug 2023 16:56:05 -0700 Subject: [PATCH] Create trie_postorder.py --- tries/trie_postorder.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tries/trie_postorder.py diff --git a/tries/trie_postorder.py b/tries/trie_postorder.py new file mode 100644 index 0000000..992e66c --- /dev/null +++ b/tries/trie_postorder.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# author: bt3gl + + +def postorder(self, root: 'Node') -> List[int]: + + 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] +