2
* Definition for a binary tree node.3
* function TreeNode(val, left, right) {4
* this.val = (val===undefined ? 0 : val)5
* this.left = (left===undefined ? null : left)6
* this.right = (right===undefined ? null : right)10
* @param {TreeNode} root12
var BSTIterator = function (root) {20
BSTIterator.prototype.next = function () {22
this.stack.push(this.node);23
this.node = this.node.left;25
const node = this.stack.pop();26
this.node = node.right;33
BSTIterator.prototype.hasNext = function () {34
return this.node || this.stack.length > 0;38
* Your BSTIterator object will be instantiated and called as such:39
* var obj = new BSTIterator(root)40
* var param_1 = obj.next()41
* var param_2 = obj.hasNext()