input: Write a python function to implement an iterator over a binary search tree (BST).
  assert BSTIterator(TreeNode(7, TreeNode(3), TreeNode(15, TreeNode(9), TreeNode(20)))).next() == 3
  assert BSTIterator(TreeNode(7, TreeNode(3), TreeNode(15, TreeNode(9), TreeNode(20)))).hasNext() == True
  assert BSTIterator(TreeNode(7, TreeNode(3), TreeNode(15, TreeNode(9), TreeNode(20)))).next() == 7
output: class TreeNode:
      def __init__(self, val=0, left=None, right=None):
          self.val = val
          self.left = left
          self.right = right
  
  class BSTIterator:
      def __init__(self, root: TreeNode):
          self.stack = []
          self._leftmost_inorder(root)
  
      def _leftmost_inorder(self, root):
          while root:
              self.stack.append(root)
              root = root.left
  
      def next(self) -> int:
          topmost_node = self.stack.pop()
          if topmost_node.right:
              self._leftmost_inorder(topmost_node.right)
          return topmost_node.val
  
      def hasNext(self) -> bool:
          return len(self.stack) > 0