5
Stack<TreeNode> st = new Stack<>();7
public BSTIterator(TreeNode root) {10
current = findLeft(root);11
// System.out.println("Init: stack is: "+st);17
if (current != null) val = current.val;20
if (current.right != null) current = findLeft(current.right);21
else if (!st.isEmpty()) current = st.pop();23
// System.out.println("next: stack is: "+st);27
public TreeNode findLeft(TreeNode node) {29
if (node == null) return null;31
if (node.left != null) {32
TreeNode next = node.left;34
return findLeft(next);38
public boolean hasNext() {39
return current != null;