mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Update and rename all_subnotes_bst.py to bst_all_subnodes.py
This commit is contained in:
parent
aca9429097
commit
6b3923e32c
@ -3,7 +3,7 @@
|
|||||||
# author: bt3gl
|
# author: bt3gl
|
||||||
|
|
||||||
|
|
||||||
class TreeNode:
|
class Node:
|
||||||
def __init__(self, val=0, left=None, right=None):
|
def __init__(self, val=0, left=None, right=None):
|
||||||
self.val = val
|
self.val = val
|
||||||
self.left = left
|
self.left = left
|
||||||
@ -26,14 +26,14 @@ def all_possible_bst(start, end, memo):
|
|||||||
|
|
||||||
for l in left:
|
for l in left:
|
||||||
for r in right:
|
for r in right:
|
||||||
root = TreeNode(i, l, r)
|
root = Node(i, l, r)
|
||||||
result.append(root)
|
result.append(root)
|
||||||
|
|
||||||
memo[(start, end)] = result
|
memo[(start, end)] = result
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def generateTrees(n) -> List[Optional[TreeNode]]:
|
def generate_trees(n):
|
||||||
|
|
||||||
memo = {}
|
memo = {}
|
||||||
return all_possible_bst(1, n, memo)
|
return all_possible_bst(1, n, memo)
|
Loading…
x
Reference in New Issue
Block a user