Create bt_preorder.py

This commit is contained in:
bt3gl 2023-08-08 13:36:59 -07:00 committed by GitHub
parent 9486e25675
commit 0e2b6b39b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

11
trees/bt_preorder.py Normal file
View 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)