mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
25 lines
419 B
Python
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]
|
|
|