@@ -0,0 +1,1016 @@
+/**%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%0A  // Use an array list to prevent having to count the # of nodes beforehand.%0A  List%3CInteger%3E list;%0A  int current;%0A  public BSTIterator(TreeNode root) %7B%0A    this.list = traverse(root, new ArrayList%3CInteger%3E());%0A    this.current = 0;%0A  %7D%0A%0A  /** @return whether we have a next smallest number */%0A  public boolean hasNext() %7B%0A    return this.current %3C this.list.size();%0A  %7D%0A%0A  /** @return the next smallest number */%0A  public int next() %7B%0A    if (this.hasNext()) return this.list.get(this.current++);%0A    return -1;%0A  %7D%0A%0A  /**%0A   * Simple in order traversal to populate the array list in sorted order.%0A   */%0A  private List%3CInteger%3E traverse(TreeNode node, List%3CInteger%3E list) %7B%0A    if (node == null) return list;%0A    traverse(node.left, list);%0A    list.add(node.val);%0A    traverse(node.right, list);%0A    return list;%0A  %7D%0A%7D%0A%0A

Add 173