@@ -0,0 +1,1207 @@
+/**%0A * Definition for binary tree%0A * public class TreeNode %7B%0A *     int val;%0A *     TreeNode left;%0A *     TreeNode right;%0A *     TreeNode(int x) %7B val = x; %7D%0A * %7D%0A */%0A%0Apublic class BSTIterator %7B%0A    private Stack%3CTreeNode%3E stack;%0A%0A    public BSTIterator(TreeNode root) %7B%0A        stack = new Stack%3C%3E();%0A        if(root!= null)%7B%0A            TreeNode cur = root;%0A            while(cur != null)%7B%0A                stack.push(cur);%0A                if(cur.left != null)%7B%0A                    cur = cur.left;%0A                %7Delse%7B%0A                    break;%0A                %7D%0A            %7D%0A%0A        %7D%0A    %7D%0A%0A    /** @return whether we have a next smallest number */%0A    public boolean hasNext() %7B%0A        return !stack.isEmpty();%0A        %0A    %7D%0A%0A    /** @return the next smallest number */%0A    public int next() %7B%0A        TreeNode node = stack.pop();%0A        TreeNode cur = node;%0A        // traversal right branch%0A        if(cur.right != null)%7B%0A            cur = cur.right;%0A            while(cur != null)%7B%0A                stack.push(cur);%0A                if(cur.left != null)%0A                    cur = cur.left;%0A                else%0A                    break;%0A            %7D%0A        %7D%0A        return node.val;%0A    %7D%0A%7D

The solution for 173