Create trie_postorder.py

This commit is contained in:
marina 2023-08-03 16:56:05 -07:00 committed by GitHub
parent 141a6b5944
commit c041716806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

21
tries/trie_postorder.py Normal file
View 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]