mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-02 06:46:18 -04:00
Create trie_postorder.py
This commit is contained in:
parent
141a6b5944
commit
c041716806
1 changed files with 21 additions and 0 deletions
21
tries/trie_postorder.py
Normal file
21
tries/trie_postorder.py
Normal file
|
@ -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]
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue