https://leetcode.com/problems/binary-search-tree-iterator


Success.

___

Runtime
73 ms

Beats
91.21%

Memory
20.8 MB

Beats
6.12%

___

```python
class BSTIterator:
    def __init__(self, root: Optional[TreeNode]):
        #2023/1/1 07:49
        self.node_list = []
        self.index = 0
        def go_through(node):
            if not node:
                return
            if node.left:
                go_through(node.left)
            self.node_list.append(node)
            #print(node.val)
            if node.right:
                go_through(node.right)
        go_through(root)
        #2023/1/1 07:56

    def next(self) -> int:
        value = self.node_list[self.index].val
        self.index += 1
        return value

    def hasNext(self) -> bool:
        if self.index < len(self.node_list):
            return True
        return False
```
