mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Create trie_postorder.py
This commit is contained in:
parent
141a6b5944
commit
c041716806
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…
x
Reference in New Issue
Block a user