Update and rename preorder_transversal.py to bt_preorder_transversal.py

This commit is contained in:
marina 2023-08-03 13:18:57 -07:00 committed by GitHub
parent 7520042ef9
commit 84b35ceaf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,9 +2,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# author: bt3gl # author: bt3gl
# recursive and iterative inorder traversal
def preorder_recursive(root: Optional[TreeNode]) -> list[int]: def preorder_recursive(root: Optional[Node]) -> list[int]:
if root == None: if root == None:
return [] return []
@ -12,7 +11,7 @@ def preorder_recursive(root: Optional[TreeNode]) -> list[int]:
return [root.val] + preorder_recursive(root.left) + preorder_recursive(root.right) return [root.val] + preorder_recursive(root.left) + preorder_recursive(root.right)
def preorder_iterative(root: Optional[TreeNode]) -> list[int]: def preorder_iterative(root: Optional[Node]) -> list[int]:
result = [] result = []
stack = [root] stack = [root]