mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Create bt_preorder.py
This commit is contained in:
parent
9486e25675
commit
0e2b6b39b0
11
trees/bt_preorder.py
Normal file
11
trees/bt_preorder.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# author: bt3gl
|
||||||
|
|
||||||
|
def preorder(root) -> list:
|
||||||
|
|
||||||
|
if root is None:
|
||||||
|
return []
|
||||||
|
|
||||||
|
return [root.val] + preorder(root.left) + preorder(root.right)
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user