mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Create trie_preorder.py
This commit is contained in:
parent
e95aa5a731
commit
141a6b5944
18
tries/trie_preorder.py
Normal file
18
tries/trie_preorder.py
Normal file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# author: bt3gl
|
||||
|
||||
|
||||
def preorder(root: 'Node'):
|
||||
|
||||
if root is None:
|
||||
return []
|
||||
|
||||
stack, result = [root, ], []
|
||||
|
||||
while stack:
|
||||
node = stack.pop()
|
||||
result.append(node.val)
|
||||
stack.extend(node.children[::-1])
|
||||
|
||||
return result
|
Loading…
x
Reference in New Issue
Block a user