Skip to content

Commit d42a61a

Browse files
author
Partho Biswas
committed
no message
1 parent bc93c6a commit d42a61a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

leetcode.com/python/173_Binary_Search_Tree_Iterator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ def hasNext(self):
4040
return self.nextIndex < len(self.nodesSorted)
4141

4242

43-
44-
45-
4643
# Approach 2: https://tinyurl.com/smu9ku3
4744
class BSTIterator(object):
4845

@@ -54,16 +51,18 @@ def __init__(self, root):
5451
self.__leftMostInorder(root)
5552

5653
def __leftMostInorder(self, root):
54+
curentStack = self.stack
5755
while root:
58-
self.stack.append(root)
56+
curentStack.append(root)
5957
root = root.left
6058

6159
def next(self):
6260
"""
6361
@return the next smallest number
6462
:rtype: int
6563
"""
66-
topMostNode = self.stack.pop()
64+
curentStack = self.stack
65+
topMostNode = curentStack.pop()
6766
if topMostNode.right:
6867
self.__leftMostInorder(topMostNode.right)
6968
return topMostNode.val
@@ -73,4 +72,5 @@ def hasNext(self):
7372
@return whether we have a next smallest number
7473
:rtype: bool
7574
"""
76-
return len(self.stack) > 0
75+
curentStack = self.stack
76+
return len(curentStack) > 0

0 commit comments

Comments
 (0)