Update and rename bst_inorder_iterator.py to bt_inorder_iterator.py

This commit is contained in:
bt3gl 2023-08-08 15:37:13 -07:00 committed by GitHub
parent d50ed323fd
commit ef073d11ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,29 +8,24 @@ class Node:
self.left = left
self.right = right
class BST_Iterator:
def __init__(self, root: Optional[Node]):
def __init__(self, root):
self.stack = []
self.left_inorder(root)
def left_inorder(self, root):
while root:
self.stack.append(root)
root = root.left
def next(self) -> int:
top_node = self.stack.pop()
if top_node.right:
self.left_inorder(top_node.right)
return top_node.val
def has_next(self) -> bool:
return len(self.stack) > 0