# Binary Search Tree Iterator(Leetcode 173)

Problem Link: <https://leetcode.com/problems/binary-search-tree-iterator/>

```python
class BSTIterator:
    
    def __init__(self, root: Optional[TreeNode]):
        self.s=[]
        self.push(root)
        
    def next(self) -> int:
        node=self.s.pop()
        self.push(node.right)
        return node.val
        
    def hasNext(self) -> bool:
        if(len(self.s)==0):
            return False
        else:
            return True
    
    def push(self,temp):
        while(temp is not None):
            self.s.append(temp)
            temp=temp.left
```
